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


import org.apache.commons.lang3.StringUtils;

public enum TaskTypeEnum {
    AR_OVERDUE("1", "arOverdue", "AP逾期"),
    WIP_OVERDUE("2", "wipOverdue", "WIP逾期"),
    TER_EXCEED_STANDARD("3", "terExceedStandard", "TER超标"),
    CONTRACT_NOT_FILED("4", "contractNotFiled", "合同未归档"),
    CODE_INACTIVITY("5", "codeInactivity", "Code不活跃");

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

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

}
