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

    START(10, "发起"),

    WAIT_TO_START(15, "待开始"),

    PROCESSING(20, "审批中"),

    PROCESSED(30, "已审批"),

    REJECT(40, "已拒绝"),

    BACK(50, "已退回"),

    CALL_BACK(60, "已撤回"),

    CLOSE(70, "已关闭"),

    TRANSFERRED(80, "已转交"),

    JUMPED(90, "已跳过");

    private final Integer code;

    private final String name;

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

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

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

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