package cn.stylefeng.workflow.api.enums.strategy;

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

    NOT_JUMP(5, "不自动跳过"),

    JUMP(10, "自动跳过"),

    TURN_TO_LEADER(20, "转交给直属上级审批"),

    @Deprecated
    TURN_TO_DEPT_LEADER(30, "转交给部门负责人审批");

    private final Integer code;

    private final String name;

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

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

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

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

}
