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


import org.apache.commons.lang3.StringUtils;

public enum DataRoleConfigTypeEnum {
    LEVEL("0", "level", "按层级"),
    CODE_BLOCK("1", "codeBlock", "按codeBlock");

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

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

}
