package com.ningdatech.carapi.common.constant;

import java.util.Objects;

import lombok.Getter;

/**
 * EducationEnum
 * @return
 * @author CMM
 * @since 2023/06/26 12:39
 */
@Getter
public enum EducationEnum {

    /**
     * 学历编码定义
     */
    PRIMARY(0, "小学"),
    JUNIOR(1, "初中"),
    HIGH(2, "高中"),
    TECHNICAL(3, "专科"),
    UNDERGRADUATE(4, "本科"),
    POSTGRADUATE(5, "研究生"),
    DOCTOR(6, "博士");

    private final int code;
    private final String value;

    EducationEnum(int code, String value) {
        this.code = code;
        this.value = value;
    }

    public boolean eq(String val) {
        return this.getValue().equals(val);
    }

    public boolean eq(int code) {
        return this.getCode() == code;
    }

    public static EducationEnum getByCode(int code) {
        for (EducationEnum genderEnum : EducationEnum.values()) {
            if (genderEnum.getCode() == code) {
                return genderEnum;
            }
        }
        return null;
    }

    public static String getDescByCode(int code) {
        for (EducationEnum genderEnum : EducationEnum.values()) {
            if (genderEnum.getCode() == code) {
                return genderEnum.getValue();
            }
        }
        return null;
    }

    public static EducationEnum getByValue(String value) {
        if (Objects.isNull(value)) {
            return null;
        }
        for (EducationEnum genderEnum : EducationEnum.values()) {
            if (genderEnum.getValue().contains(value)) {
                return genderEnum;
            }
        }
        return null;
    }

}
