package com.red.circle.other.infra.database.mongo.entity.live;

import com.red.circle.other.inner.model.dto.material.UseBadgeDTO;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.mongodb.core.mapping.Document;

/**
 * <p>
 * 房间资料管理.
 * </p>
 *
 * @author penglaing
 * @since 2022/6/24
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Document("room_profile_manager")
public class RoomProfileManager extends RoomProfile implements Serializable {

  @Serial
  private static final long serialVersionUID = 1L;

  /**
   * 房间设置.
   */
  private RoomSetting setting;

  /**
   * 房间计数器.
   */
  private RoomCounter counter;

  /**
   * 自定义设置.
   */
  private Map<String, String> customizeSetting;

  /**
   * 房间装配徽章.
   */
  private List<UseBadgeDTO> useBadges;

  public List<UseBadgeDTO> filterBadges(Predicate<UseBadgeDTO> predicate) {
    return Optional.ofNullable(useBadges)
        .map(usePropsEntities -> usePropsEntities.stream()
            .filter(Objects::nonNull)
            .filter(predicate)
            .collect(Collectors.toList()))
        .orElse(null);
  }


  public boolean checkAdminOverflow() {
    return counter.getAdminCount() >= setting.getMaxAdmin();
  }

  public boolean checkMemberOverflow() {
    return counter.getMemberCount() >= setting.getMaxMember();
  }

}
