import {BaseResponse, BaseQuery} from '@/types/base';

export interface WorkflowDefinition extends BaseResponse {
    id: number;
    name: string;
    key: string;
    description?: string;
    flowVersion?: number;
    status?: string;
    categoryId?: number;  // 分类ID
    triggers: string[];
    graph: {
        nodes: WorkflowDefinitionNode[];
        edges: any[];
    };
    formConfig: {
        formItems: any[];
    };
    formVariablesSchema?: {
        type: string;
        required?: string[];
        properties: {
            [key: string]: {
                type: string;
                title: string;
                description?: string;
                dataSource?: {
                    url: string;
                    type: string;
                    params?: Record<string, any>;
                    dependsOn?: string[];
                    labelField?: string;
                    valueField?: string;
                };
            };
        };
    };
    bpmnXml?: string;
}

export interface WorkflowDefinitionNode {
    id: number | string;          // 支持数字或UUID字符串
    nodeCode: string;
    nodeType: string;
    nodeName: string;
    position?: { x: number; y: number };  // 节点位置
    configs?: Record<string, any>;        // 基本配置
    inputMapping?: Record<string, any>;   // 输入映射
    outputs?: Array<{                     // 输出能力定义
        name: string;
        title: string;
        type: 'string' | 'number' | 'boolean' | 'object' | 'array';  // 与 OutputField 保持一致
        description: string;
        enum?: string[];
        example?: any;
        required?: boolean;
    }>;
}

export interface WorkflowDefinitionQuery extends BaseQuery {
    name?: string;
    key?: string;
    categoryId?: number;  // 分类ID筛选
    status?: string;
}

/**
 * 工作流分类响应
 */
export interface WorkflowCategoryResponse {
    id: number;
    name: string;
    code: string;
    description?: string;
    icon?: string;
    sort: number;
    supportedTriggers?: string[];  // 触发方式代码列表，如 ["MANUAL","SCHEDULED"]
    enabled: boolean;
    createBy?: string;
    createTime?: string;
    updateBy?: string;
    updateTime?: string;
}

/**
 * 工作流分类查询参数
 */
export interface WorkflowCategoryQuery extends BaseQuery {
    name?: string;
    code?: string;
    enabled?: boolean;
}

/**
 * 工作流分类创建/更新请求
 */
export interface WorkflowCategoryRequest {
    name: string;
    code: string;
    description?: string;
    icon?: string;
    sort?: number;
    supportedTriggers?: string[];
    enabled?: boolean;
}
