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

    EXE_BEFORE(10, "执行前"),

    EXE_SUCCESS(20, "执行成功后"),

    EXE_ERROR(21, "执行失败后"),

    APPROVAL_PASSED(30, "审批全部通过后"),

    REJECT_PASSED(31, "审批拒绝后");

    private final Integer code;

    private final String name;

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

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

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

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