package com.red.circle.common.business.enums;

import java.util.Arrays;
import java.util.Objects;

/**
 * 性别枚举
 *
 * @author pengliang
 * @since 2019/11/6 16:05
 */
public enum GenderEnum {
  /****/
  UNDEFINED(-1, "未定义"),
  FEMALE(0, "女"),
  MALE(1, "男");

  private final int value;
  private final String name;

  GenderEnum(int value, String name) {
    this.value = value;
    this.name = name;
  }

  public static GenderEnum getGenderEnum(Integer value) {
    return Arrays.stream(GenderEnum.values())
        .filter(genderEnum -> Objects.equals(genderEnum.getValue(), value))
        .findFirst()
        .orElse(GenderEnum.UNDEFINED);
  }

  public static boolean isMale(Integer value) {
    return Objects.equals(value, GenderEnum.MALE.getValue());
  }

  public static boolean isFemale(Integer value) {
    return Objects.equals(value, GenderEnum.FEMALE.getValue());
  }

  public int getValue() {
    return value;
  }

  public String getName() {
    return name;
  }

  public boolean isFemale() {
    return Objects.equals(FEMALE, this);
  }

  public boolean isMale() {
    return Objects.equals(MALE, this);
  }

  public GenderEnum reverse() {
    return Objects.equals(this, MALE) ? FEMALE : MALE;
  }
}
