/** Workflow 编排 DSL（前端 MVP，静态页 / 后续持久化共用） */

export interface WorkflowViewport {
  x: number
  y: number
  zoom: number
}

export interface WorkflowNodeDef {
  id: string
  type: string
  label: string
  position: { x: number; y: number }
  params: Record<string, unknown>
  /** 导出 JSON 时写入：下一节点 ID（单出口 / 成立 / 正常执行） */
  nextId?: string | null
  /** 导出 JSON 时写入：条件不成立时的下一节点 ID */
  failNextId?: string | null
  /** 导出 JSON 时写入：超时执行时的下一节点 ID */
  timeoutNextId?: string | null
}

export interface WorkflowEdgeDef {
  id: string
  source: string
  target: string
  sourceHandle?: string
  label?: string
}

export interface WorkflowDefinition {
  id: string
  name: string
  version: number
  nodes: WorkflowNodeDef[]
  edges: WorkflowEdgeDef[]
  viewport?: WorkflowViewport
}

export interface WorkflowCatalog {
  workflows: WorkflowDefinition[]
  activeWorkflowId?: string
}

export type ParamFieldType = 'string' | 'number' | 'boolean' | 'select' | 'textarea'

export interface ParamFieldDef {
  key: string
  label: string
  type: ParamFieldType
  required?: boolean
  defaultValue?: unknown
  placeholder?: string
  options?: Array<{ label: string; value: string | number | boolean }>
  /** 仅当节点 params[when.key] === when.equals 时显示该表单项 */
  when?: { key: string; equals: string | number | boolean }
}

export interface NodeTypeDef {
  type: string
  label: string
  category: string
  description?: string
  color?: string
  singleton?: boolean
  params: ParamFieldDef[]
}
