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


import org.apache.commons.lang3.StringUtils;

public enum SpecialConditionEnum {
    //1.满足以下所有条件 2.满足以下任一条件 3.无
    ALL("1", "all", "满足以下所有条件"),
    ANY("2", "any", "满足以下任一条件"),
    NO("3", "no", "无"),
    ;

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

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

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

}
