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

    NONE(-10, "空状态"),

    NOT_RUN(10, "未进行"),

    RUNNING(20, "进行中"),

    FINISH(30, "已完成"),

    SKIP(40, "已跳过"),

    REJECT(50, "已拒绝"),

    BACK(60, "已退回"),

    TURN(70, "已转交");

    private final Integer status;

    private final String name;

    NodeStatusEnum(int status, String name) {
        this.status = status;
        this.name = name;
    }

    @Override
    public Object getKey() {
        return this.status;
    }

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