package cn.stylefeng.workflow.api.enums.subflow;

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

    MAIN_FLOW_APPLICANT(1, "主流程发起人"),

    POINT_USER(2, "指定成员"),

    FORM_VARIABLE(3, "来自表单字段"),

    MODEL_VARIABLE(4, "来自流程变量");

    private final Integer code;

    private final String name;

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

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

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