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

    PAGE_START(10, "页面发起"),

    API_START(20, "接口发起");

    private final Integer code;

    private final String name;

    WorkflowStartTypeEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

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

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