import {ConfigurableNodeDefinition, NodeType, NodeCategory, defineNodeOutputs} from './types';
import { DataSourceType } from '@/domain/dataSource';

/**
 * Jenkins构建节点定义（纯配置）
 * 使用 BaseNode 组件渲染，无需自定义渲染代码
 */
export const JenkinsBuildNodeDefinition: ConfigurableNodeDefinition = {
    nodeCode: "JENKINS_BUILD",
    nodeName: "Jenkins构建",
    nodeType: NodeType.JENKINS_BUILD,
    category: NodeCategory.TASK,
    description: "通过Jenkins执行构建任务",

    // 渲染配置（配置驱动）
    renderConfig: {
        shape: 'rounded-rect',
        size: {width: 140, height: 48},
        icon: {
            type: 'emoji',
            content: '🔨',
            size: 32
        },
        theme: {
            primary: '#f59e0b',
            secondary: '#d97706',
            selectedBorder: '#3b82f6',
            hoverBorder: '#f59e0b',
            gradient: ['#ffffff', '#fef3c7']
        },
        handles: {
            input: true,
            output: true
        },
        features: {
            showBadge: true,
            showHoverMenu: true
        }
    },

    // 基本配置Schema（仅业务配置，元数据已移至固定表单）
    inputMappingSchema: {
        type: "object",
        title: "输入",
        description: "当前节点所需数据配置",
        properties: {
            jenkinsServerId: {
                type: "number",
                title: "服务器",
                description: "选择要使用的服务器",
                'x-dataSource': DataSourceType.JENKINS_SERVERS
            },
            project: {
                type: "string",
                title: "项目",
                description: "要触发构建的项目",
                default: ""
            },
        },
        required: ["jenkinsServerId"]
    },
    outputs: defineNodeOutputs(
        {
            name: "buildNumber",
            title: "构建编号",
                type: "number",
            description: "Jenkins构建的唯一编号",
            example: 123,
            required: true
        },
        {
            name: "buildUrl",
            title: "构建URL",
                type: "string",
            description: "Jenkins构建页面的访问地址",
            example: "http://jenkins.example.com/job/app/123/",
            required: true
        },
        {
            name: "artifactUrl",
            title: "构建产物地址",
                type: "string",
            description: "构建生成的jar/war包下载地址",
            example: "http://jenkins.example.com/job/app/123/artifact/target/app-1.0.0.jar",
            required: false
        },
        {
            name: "gitCommitId",
            title: "Git提交ID",
                type: "string",
            description: "本次构建使用的Git提交哈希值",
            example: "a3f5e8d2c4b1a5e9f2d3e7b8c9d1a2f3e4b5c6d7",
            required: true
        },
        {
            name: "buildDuration",
            title: "构建时长",
                type: "number",
            description: "构建执行的时长（秒）",
            example: 120,
            required: true
        }
    )
};

// ✅ 不再需要单独的渲染组件，使用 BaseNode 即可
