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

    START(10, "流程开始"),

    END(20, "流程结束"),

    SUSPEND(30, "流程挂起"),

    ACTIVE(40, "流程激活"),

    RECALL(50, "流程撤回");

    private final Integer code;

    private final String name;

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

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

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

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