/**
 * Types for the Background Task Queue.
 */

export type QueuedTaskStatus =
  | 'pending'
  | 'running'
  | 'completed'
  | 'failed'
  | 'cancelled'

export interface QueuedTask {
  id: string
  prompt: string
  status: QueuedTaskStatus
  /** Git worktree branch name */
  worktreeBranch?: string
  /** Git worktree path */
  worktreePath?: string
  /** When the task was queued */
  queuedAt: number
  /** When the task started running */
  startedAt?: number
  /** When the task finished */
  completedAt?: number
  /** Token budget for this task */
  tokenBudget: number
  /** Tokens consumed so far */
  tokensUsed: number
  /** Result summary (generated on completion) */
  summary?: TaskSummary
  /** Error message if failed */
  error?: string
}

export interface TaskSummary {
  /** Files that were changed */
  filesChanged: Array<{ path: string; description: string }>
  /** Tests that were run */
  testsRun: Array<{ name: string; passed: boolean }>
  /** Decisions made during execution */
  decisions: string[]
  /** Overall confidence: high, medium, low */
  confidence: 'high' | 'medium' | 'low'
  /** Whether the result needs human review */
  needsReview: boolean
  /** Human-readable summary */
  text: string
}

export interface QueueState {
  version: 1
  tasks: QueuedTask[]
  /** Maximum concurrent tasks */
  maxConcurrent: number
  /** Default token budget per task */
  defaultTokenBudget: number
}

export function createFreshQueueState(): QueueState {
  return {
    version: 1,
    tasks: [],
    maxConcurrent: 3,
    defaultTokenBudget: 200_000,
  }
}
