export interface ChatMessage {
  id: string
  role: 'user' | 'assistant'
  content: string
  timestamp: number
  isStreaming?: boolean
}

export interface AIDesignRequest {
  prompt: string
  context?: {
    selectedNodes?: string[]
    documentSummary?: string
    canvasSize?: { width: number; height: number }
    variables?: Record<string, import('@/types/variables').VariableDefinition>
    themes?: Record<string, string[]>
  }
}

export interface AICodeRequest {
  prompt?: string
  format: 'react-tailwind' | 'html-css' | 'react-inline'
  nodeIds?: string[]
}

export interface AIStreamChunk {
  type: 'text' | 'thinking' | 'done' | 'error' | 'ping'
  content: string
}

// ---------------------------------------------------------------------------
// Orchestrator types — used for parallel sub-agent design generation
// ---------------------------------------------------------------------------

/** A sub-task produced by the orchestrator (lightweight — only spatial info) */
export interface SubTask {
  /** Unique ID for this sub-task, e.g. "sidebar", "header" */
  id: string
  /** Human-readable label for progress UI */
  label: string
  /** Spatial region allocated on the canvas */
  region: { width: number; height: number }
  /** ID prefix for all nodes generated by this sub-agent (assigned at runtime) */
  idPrefix: string
  /** Parent frame ID to insert into (assigned at runtime) */
  parentFrameId: string | null
}

/** Plan produced by the orchestrator (lightweight — only structure) */
export interface OrchestratorPlan {
  rootFrame: {
    id: string
    name: string
    width: number
    height: number
    layout?: 'none' | 'vertical' | 'horizontal'
    gap?: number
    fill?: Array<{ type: string; color: string }>
  }
  subtasks: SubTask[]
}

/** Progress state for the orchestrated generation */
export interface OrchestrationProgress {
  phase: 'planning' | 'generating' | 'merging' | 'done' | 'error'
  subtasks: Array<{
    id: string
    label: string
    status: 'pending' | 'streaming' | 'done' | 'error'
    nodeCount: number
  }>
  totalNodes: number
}

/** Result from a single sub-agent */
export interface SubAgentResult {
  subtaskId: string
  nodes: import('@/types/pen').PenNode[]
  rawResponse: string
  error?: string
}
