// ─── TypeScript Types ───────────────────────────────────────────────────────

export interface WorkflowNode {
  id: string;
  type: string;
  label: string;
  position: { x: number; y: number };
  config: Record<string, any>;
  instanceRef?: {
    instanceId: string;
    instanceName: string;
  };
}

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

export interface WorkflowDSL {
  nodes: WorkflowNode[];
  edges: WorkflowEdge[];
}

export interface AgentOutput {
  dsl: WorkflowDSL;
  changeSummary: string;
}

export interface Workflow {
  id: string;
  name: string;
  description: string | null;
  status: 'DRAFT' | 'PUBLISHED';
  isEnabled: boolean;
  dsl: WorkflowDSL | null;
  creator: string;
  createdAt: string;
  updatedAt: string;
  versions?: { version: number; changeSummary?: string | null }[];
  _count?: { instances: number };
  runs?: {
    pending: number;
    running: number;
    completed: number;
    failed: number;
  };
  lastRun?: string | null;
}

export interface WorkflowVersion {
  id: string;
  version: number;
  dsl: WorkflowDSL;
  prompt: string;
  changeSummary: string | null;
  creator: string;
  createdAt: string;
}

export interface WorkflowOverview {
  totalRuns: { last24h: number; total: number };
  successRate: { last24h: number; total: number };
  failed: { last24h: number; total: number };
  duration: {
    last24h: { avg: number; p95: number };
    total: { avg: number; p95: number };
  };
  running: number;
  pending: number;
}

export interface WorkflowNodeType {
  id: string;
  type: string;
  category: string;
  label: string;
  icon: string;
  description: string | null;
  configSchema: Record<string, any>;
  inputSchema: Record<string, any>;
  outputSchema: Record<string, any>;
}

export interface NodeInstanceAgentOutput {
  name: string;
  description: string;
  config: Record<string, any>;
}
