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 ApproverTypeEnum implements ReadableEnum<ApproverTypeEnum> {

    ORG_SELECT(10, "从组织库中选择"),

    FORM_SELECT(20, "从表单中获取"),

    VARIABLE_SELECT(30, "从流程变量获取"),

    SUBMITTER_SELF(40, "发起人自己"),

    CUSTOM_RULE(50, "自定义规则"),

    OPTION_CHOICE(60, "自由选择");

    private final Integer value;

    private final String name;

    ApproverTypeEnum(Integer value, String name) {
        this.value = value;
        this.name = name;
    }

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

    @Override
    public Object getName() {
        return name;
    }

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

}
