package com.qqchen.deploy.backend.workflow.enums;

import com.fasterxml.jackson.annotation.JsonValue;
import com.qqchen.deploy.backend.workflow.dto.definition.node.localVariables.DeployNodeLocalVariables;
import com.qqchen.deploy.backend.workflow.dto.definition.node.localVariables.NotificationNodeLocalVariables;
import com.qqchen.deploy.backend.workflow.dto.definition.node.localVariables.ScriptNodeLocalVariables;
import com.qqchen.deploy.backend.workflow.dto.definition.node.panelVariables.DeployNodePanelVariables;
import com.qqchen.deploy.backend.workflow.dto.definition.node.panelVariables.EndNodePanelVariables;
import com.qqchen.deploy.backend.workflow.dto.definition.node.panelVariables.GatewayNodePanelVariables;
import com.qqchen.deploy.backend.workflow.dto.definition.node.panelVariables.NotificationNodePanelVariables;
import com.qqchen.deploy.backend.workflow.dto.definition.node.panelVariables.ScriptNodePanelVariables;
import com.qqchen.deploy.backend.workflow.dto.definition.node.panelVariables.StartNodePanelVariables;
import com.qqchen.deploy.backend.workflow.dto.definition.node.panelVariables.ApprovalNodePanelVariables;
import com.qqchen.deploy.backend.workflow.dto.definition.node.uiVariables.NodeUiVariables;
import lombok.Getter;

/**
 * 工作节点类型枚举
 * 定义了工作流中所有可用的节点类型及其UI配置
 */
@Getter
public enum NodeTypeEnums {

    /**
     * 开始节点
     * 工作流的起点，每个流程必须有且仅有一个开始节点
     * 特点:
     * - 只能有出边，不能有入边
     * - 用于触发工作流的执行
     */
    START_EVENT(
        "START_EVENT",                // 节点类型编码
        "开始节点",                    // 节点显示名称
        BpmnNodeTypeEnums.START_EVENT,
        NodeCategoryEnums.EVENT,
        "工作流开始"
    ),

    /**
     * 结束节点
     * 工作流的终点，每个流程必须有且仅有一个结束节点
     * 特点:
     * - 只能有入边，不能有出边
     * - 标志着工作流的结束
     */
    END_EVENT(
        "END_EVENT",
        "结束节点",
        BpmnNodeTypeEnums.END_EVENT,
        NodeCategoryEnums.EVENT,
        "工作流结束"
    ),
    JENKINS_BUILD(
        "JENKINS_BUILD",
        "Jenkins构建",
        BpmnNodeTypeEnums.SERVICE_TASK,
        NodeCategoryEnums.TASK,
        "Jenkins构建任务"
    ),
    SCRIPT_NODE(
        "SCRIPT_NODE",
        "脚本任务",
        BpmnNodeTypeEnums.SERVICE_TASK,
        NodeCategoryEnums.TASK,
        "脚本执行任务"
    ),
    DEPLOY_NODE(
        "DEPLOY_NODE",
        "构建任务",
        BpmnNodeTypeEnums.SERVICE_TASK,
        NodeCategoryEnums.TASK,
        "构建任务"
    ),
    GATEWAY_NODE(
        "GATEWAY_NODE",
        "网关节点",
        BpmnNodeTypeEnums.EXCLUSIVE_GATEWAY,
        NodeCategoryEnums.GATEWAY,
        "条件分支控制"
    ),
    NOTIFICATION(
        "NOTIFICATION",
        "通知节点",
        BpmnNodeTypeEnums.SERVICE_TASK,
        NodeCategoryEnums.TASK,
        "通知节点"
    ),
    APPROVAL(
        "APPROVAL",
        "审批节点",
        BpmnNodeTypeEnums.USER_TASK,
        NodeCategoryEnums.TASK,
        "人工审批节点，支持多种审批模式"
    );

    @JsonValue
    private final String code;            // 节点类型编码

    private final String name;            // 节点显示名称

    private final BpmnNodeTypeEnums bpmnType; // 对应的BPMN类型

    private final NodeCategoryEnums category; //分类

    private final String description;     // 节点详细描述

    NodeTypeEnums(
        String code,
        String name,
        BpmnNodeTypeEnums bpmnType,
        NodeCategoryEnums category,
        String description
    ) {
        this.code = code;
        this.name = name;
        this.bpmnType = bpmnType;
        this.category = category;
        this.description = description;
    }

    /**
     * 根据编码查找对应的枚举
     *
     * @param code 节点类型编码
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 当找不到对应的枚举值时抛出
     */
    public static NodeTypeEnums fromValue(String code) {
        for (NodeTypeEnums type : values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown NodeType code: " + code);
    }
}
