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

    START(10, "开始节点"),

    END(11, "结束节点"),

    SUB_PROCESS(12, "子流程"),

    APPLICANT(13, "发起人"),

    MESSAGE_LISTENER(20, "消息监听"),

    USER_APPROVAL(30, "审批"),

    COPY_TO(31, "抄送"),

    HANDLE(32, "办理"),

    CUSTOM_ACTIVITY(40, "自定义活动"),

    CONDITION_GATEWAY(50, "条件网关"),

    PARALLEL_GATEWAY(51, "并行网关"),

    EVENT_GATEWAY(52, "事件网关"),

    CONDITION_GATEWAY_CONDITION(60, "条件"),

    PARALLEL_JOIN(61, "并行网关-汇合"),

    EVENT_GATEWAY_EVENT(62, "事件网关-事件"),

    CODE_PULL(601, "代码拉取"),

    UPLOAD_BUILD(602, "程序包发布"),

    FRONT_BUILD(603, "前端编译"),

    BACKEND_BUILD(604, "后端编译"),

    SHELL_BUILD(605, "shell构建"),

    UPLOAD_TO_SERVER(606, "上传到服务器"),

    RUN_JAVA(607, "运行java服务");

    private final Integer nodeType;

    private final String name;

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

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

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