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

    CURRENT_FLOW(1, "本流程日志"),

    SUB_FLOW(2, "子流程日志"),

    PARENT_FLOW(3, "父流程日志");

    private final Integer code;

    private final String name;

    FlowApprovalTypeEnum(Integer nodeType, String name) {
        this.code = nodeType;
        this.name = name;
    }

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

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