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

    PERCENT(10, "超过多少%，自动离开"),

    SUPER_NUMBER(20, "参与者超过几个已处理"),

    ONE_COMMIT(30, "某个参与者已处理"),

    MANY_COMMIT(40, "指定参与者全部处理"),

    EXPAND_CLASS(50, "拓展规则");

    private final Integer code;

    private final String name;

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

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

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

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

}
