package cn.ey.biz.module.system.enums.engagement;


import org.apache.commons.lang3.StringUtils;

public enum DateTypeEnum {
    CODE_CREATE("1", "codeCreate", "Code创建"),
    FIRST_CHARGE("2", "firstCharge", "第一次Charge");

    DateTypeEnum(String value, String code, String name) {
        this.value = value;
        this.code = code;
        this.name = name;
    }

    private final String value;
    private final String code;
    private final String name;

    public String getValue() {
        return value;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    /**
     * 用于spring-validation验证
     *
     * @param value value
     * @return Boolean
     */
    public static Boolean isValidByValue(String value) {
        for (DateTypeEnum dateTypeEnum : DateTypeEnum.values()) {
            if (value.equals(dateTypeEnum.getValue())) {
                return true;
            }
        }
        return false;
    }

    /**
     * 根据code 获取name
     *
     * @param code code
     * @return name
     */
    public static String getNameByCode(String code) {
        for (DateTypeEnum typeEnum : DateTypeEnum.values()) {
            if (StringUtils.equals(code, typeEnum.getCode())) {
                return typeEnum.getName();
            }
        }
        return null;
    }

    public static String getNameByValue(String value) {
        for (DateTypeEnum typeEnum : DateTypeEnum.values()) {
            if (value.equals(typeEnum.getValue())) {
                return typeEnum.getName();
            }
        }
        return null;
    }
}
