import {ConfigurableNodeDefinition, NodeType, NodeCategory, defineNodeOutputs} from './types';

/**
 * Git同步检测节点定义（纯配置）
 * 检测源分支与目标分支的同步状态
 */
export const GitSyncCheckNodeDefinition: ConfigurableNodeDefinition = {
    nodeCode: "GIT_SYNC_CHECK",
    nodeName: "Git同步检测",
    nodeType: NodeType.GIT_SYNC_CHECK,
    category: NodeCategory.TASK,
    description: "检测源分支与目标分支的同步状态",

    // 渲染配置
    renderConfig: {
        shape: 'rounded-rect',
        size: {width: 140, height: 48},
        icon: {
            type: 'emoji',
            content: '🔄',  // 同步图标
            size: 32
        },
        theme: {
            primary: '#3b82f6',      // 蓝色主题，与Git同步的视觉一致
            secondary: '#2563eb',
            selectedBorder: '#3b82f6',
            hoverBorder: '#60a5fa',
            gradient: ['#ffffff', '#dbeafe']
        },
        handles: {
            input: true,
            output: true
        },
        features: {
            showBadge: true,
            showHoverMenu: true
        }
    },

    // 输入配置Schema
    inputMappingSchema: {
        type: "object",
        title: "输入",
        description: "Git同步检测配置",
        properties: {
            continueOnFailure: {
                type: "boolean",
                title: "失败后继续",
                description: "true: 发现差异时标记为FAILURE，但继续执行；false: 发现差异时抛出BpmnError，终止流程",
                default: true
            },
            sourceGitSystemId: {
                type: "string",
                title: "源Git系统",
                description: "源Git系统ID（输入变量，如 ${teamApplication.sourceGitSystemId}）",
                "x-allow-variable": true,
                "x-placeholder": "${teamApplication.sourceGitSystemId}"
            },
            sourceGitProjectId: {
                type: "string",
                title: "源Git项目",
                description: "源仓库项目ID（输入变量，如 ${teamApplication.sourceGitProjectId}）",
                "x-allow-variable": true,
                "x-placeholder": "${teamApplication.sourceGitProjectId}"
            },
            sourceBranch: {
                type: "string",
                title: "源分支",
                description: "源分支名称（输入变量，如 ${teamApplication.sourceBranch}）",
                "x-allow-variable": true,
                "x-placeholder": "${teamApplication.sourceBranch}"
            },
            targetGitSystemId: {
                type: "string",
                title: "目标Git系统",
                description: "目标Git系统ID（输入变量，如 ${teamApplication.targetGitSystemId}）",
                "x-allow-variable": true,
                "x-placeholder": "${teamApplication.targetGitSystemId}"
            },
            targetGitProjectId: {
                type: "string",
                title: "目标Git项目",
                description: "目标仓库项目ID（输入变量，如 ${teamApplication.targetGitProjectId}）",
                "x-allow-variable": true,
                "x-placeholder": "${teamApplication.targetGitProjectId}"
            },
            targetBranch: {
                type: "string",
                title: "目标分支",
                description: "目标分支名称（输入变量，如 ${teamApplication.targetBranch}）",
                "x-allow-variable": true,
                "x-placeholder": "${teamApplication.targetBranch}"
            }
        },
        required: ["sourceGitSystemId", "sourceGitProjectId", "sourceBranch", "targetGitSystemId", "targetGitProjectId", "targetBranch"]
    },

    // 输出定义
    outputs: defineNodeOutputs(
        {
            name: "hasDifference",
            title: "是否存在差异",
            type: "boolean",
            description: "源分支和目标分支是否存在代码差异",
            example: true,
            required: true
        },
        {
            name: "commitsAhead",
            title: "源分支领先提交数",
            type: "number",
            description: "源分支比目标分支多出的提交数量",
            example: 5,
            required: true
        },
        {
            name: "commitsBehind",
            title: "目标分支领先提交数",
            type: "number",
            description: "目标分支比源分支多出的提交数量",
            example: 0,
            required: true
        },
        {
            name: "differenceCommits",
            title: "差异提交列表",
            type: "array",
            description: "差异提交详情列表（最多显示20条）",
            example: [
                {
                    "commitId": "a3f5e8d",
                    "message": "feat: 添加新功能",
                    "author": "张三",
                    "commitTime": "2025-12-04 10:30:00"
                }
            ],
            required: false
        },
        {
            name: "sourceLatestCommit",
            title: "源分支最新提交SHA",
            type: "string",
            description: "源分支最新提交的完整SHA值",
            example: "a3f5e8d2c4b1a5e9f2d3e7b8c9d1a2f3e4b5c6d7",
            required: true
        },
        {
            name: "targetLatestCommit",
            title: "目标分支最新提交SHA",
            type: "string",
            description: "目标分支最新提交的完整SHA值",
            example: "b2e4c7f8d1a3e5b9c2d6f9a8e7d1c4b5a3f6e8d2",
            required: true
        },
        {
            name: "checkDetail",
            title: "检查结果详情",
            type: "string",
            description: "检查结果的详细说明（用于通知模板）",
            example: "源分支 'develop' 领先目标分支 'master' 5个提交，需要同步代码",
            required: true
        }
    )
};

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