package cn.stylefeng.workflow.api.enums;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.rule.base.ReadableEnum;
import lombok.Getter;

@Getter
public enum FlowAuthLinkTypeEnum implements ReadableEnum<FlowAuthLinkTypeEnum> {

    ALL(0, "全部数据"),

    ORG(10, "机构"),

    USER(20, "人员"),

    ROLE(30, "角色");

    private final Integer type;

    private final String name;

    FlowAuthLinkTypeEnum(Integer type, String name) {
        this.type = type;
        this.name = name;
    }

    @Override
    public Object getKey() {
        return type;
    }

    @Override
    public FlowAuthLinkTypeEnum parseToEnum(String originValue) {
        if (ObjectUtil.isEmpty(originValue)) {
            return null;
        }
        for (FlowAuthLinkTypeEnum value : FlowAuthLinkTypeEnum.values()) {
            if (value.type.equals(Convert.toInt(originValue))) {
                return value;
            }
        }
        return null;
    }
}
