// ─── DSL Types (mirrors frontend WorkflowDSL) ─────────────────────────────────

import type { NodeType } from './node-types';

export interface DslNode {
  id: string;
  type: NodeType;
  label: string;
  position: { x: number; y: number };
  config: Record<string, any>;
}

export interface DslEdge {
  id: string;
  source: string;
  target: string;
  sourceHandle?: string; // for condition branches: "true"/"false" or case labels
  label?: string;
}

export interface WorkflowDSL {
  nodes: DslNode[];
  edges: DslEdge[];
}

// ─── Workflow Execution Types ──────────────────────────────────────────────────

export interface WorkflowInput {
  instanceId: number;
  workflowId: number;
  versionId: number;
  dsl: WorkflowDSL;
  context: Record<string, any>;
}

export interface WorkflowResult {
  status: 'COMPLETED' | 'FAILED' | 'CANCELLED';
  context: Record<string, any>;
  error?: string;
}

// ─── Node Execution Context ───────────────────────────────────────────────────

export interface NodeExecutionResult {
  output: Record<string, any>;
  branch?: string; // For condition nodes: which branch to take
}

export type NodeStatus = 'PENDING' | 'RUNNING' | 'COMPLETED' | 'FAILED' | 'CANCELLED';

// ─── Activity Input Types ─────────────────────────────────────────────────────

export interface ReportNodeStatusInput {
  instanceId: number;
  nodeId: string;
  nodeType: string;
  nodeLabel?: string;
  status: NodeStatus;
  input?: Record<string, any>;
  output?: Record<string, any>;
  error?: Record<string, any>;
}

export interface ReportWorkflowStatusInput {
  instanceId: number;
  status: 'RUNNING' | 'COMPLETED' | 'FAILED' | 'CANCELLED';
  result?: Record<string, any>;
}

// ─── Signals ──────────────────────────────────────────────────────────────────

export interface ApprovalSignalPayload {
  nodeId: string;
  approved: boolean;
  comment?: string;
  approvedBy: string;
}
