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


import org.apache.commons.lang3.StringUtils;

public enum CompareTypeEnum {
    EQ("1", "eq", "=="),
    NE("2", "ne", "!="),
    LE("3", "le", "=<"),
    GE("4", "ge", ">="),
    ;

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

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

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

}
