package com.red.circle.other.infra.enums.user.user;

import java.util.Locale;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;

/**
 * CP family relationship type.
 */
public enum CpRelationshipType {

  /**
   * Couple, requires different genders.
   */
  CP,

  /**
   * Brothers.
   */
  BROTHER,

  /**
   * Sisters.
   */
  SISTERS;

  public static CpRelationshipType of(String value) {
    if (StringUtils.isBlank(value)) {
      return CP;
    }
    String normalized = value.trim().toUpperCase(Locale.ROOT);
    if (Objects.equals(normalized, "BROTHERS")) {
      return BROTHER;
    }
    if (Objects.equals(normalized, "SISTER")) {
      return SISTERS;
    }
    return CpRelationshipType.valueOf(normalized);
  }

  public static String normalize(String value) {
    return of(value).name();
  }

  public boolean genderMatched(Integer sendUserSex, Integer acceptUserSex) {
    return switch (this) {
      case CP -> !Objects.equals(sendUserSex, acceptUserSex);
      case BROTHER, SISTERS -> true;
    };
  }

  public String applyTargetText() {
    return switch (this) {
      case CP -> "a couple";
      case BROTHER -> "brothers";
      case SISTERS -> "sisters";
    };
  }

  public int maxCount() {
    return switch (this) {
      case CP -> 1;
      case BROTHER, SISTERS -> 3;
    };
  }
}
