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


import org.apache.commons.lang3.StringUtils;

public enum SubConditionEnum {
    //1.winRate 2.globalServiceCode 3.riskLevel 4.businessAmount 5.erpPercentage
    WIN_RATE("1", "winRate", "WIN Rate"),
    GLOBAL_SERVICE_CODE("2", "globalServiceCode", "Global Service Code"),
    RISK_LEVEL("3", "riskLevel", "风险等级"),
    BUSINESS_AMOUNT("4", "businessAmount", "商机金额"),
    ERP_PERCENTAGE("5", "erpPercentage", "ERP%"),
    ;

    SubConditionEnum(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 (SubConditionEnum taskTypeEnum : SubConditionEnum.values()) {
            if (value.equals(taskTypeEnum.getValue())) {
                return true;
            }
        }
        return false;
    }

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

    public static SubConditionEnum getByValue(String value) {
        for (SubConditionEnum taskTypeEnum : SubConditionEnum.values()) {
            if (taskTypeEnum.value.equals(value)) {
                return taskTypeEnum;
            }
        }
        return null;
    }

}
