// ── Branches ──

export interface BranchResponse {
  id: string
  session_id: string
  parent_branch_id: string | null
  fork_point_step_id: string | null
  branch_order: number
  label: string
  status: 'active' | 'dead_end' | 'solved' | 'untried' | 'revived'
  status_reason: string | null
  status_changed_at: string | null
  context_summary: {
    tried: string[]
    concluded: string
    artifacts: string[]
  } | null
  evidence_from_branch_id: string | null
  evidence_description: string | null
  step_count: number
  created_at: string
  updated_at: string
}

export interface BranchTreeResponse {
  branches: BranchResponse[]
  active_branch_id: string | null
}

export interface ForkOption {
  label: string
  description: string
}

export interface ForkCreateRequest {
  fork_reason: string
  options: ForkOption[]
}

export interface ForkPointResponse {
  id: string
  session_id: string
  parent_branch_id: string
  trigger_step_id: string | null
  fork_reason: string
  options: Array<{
    label: string
    description: string
    branch_id: string
    status: string
  }>
  created_at: string
}

export interface BranchSwitchResponse {
  active_branch_id: string
  branch: BranchResponse
  conversation_messages: Array<{ role: string; content: string }>
}

export interface ReviveRequest {
  evidence_from_branch_id: string
  evidence_description: string
}

export interface BranchMessageRequest {
  message: string
  upload_ids?: string[]
}

export interface BranchMessageResponse {
  content: string
  branch_id: string
  step_id: string | null
}

// ── Handoffs ──

export interface HandoffCreateRequest {
  intent: 'park' | 'escalate'
  engineer_notes?: string
  priority?: 'normal' | 'elevated'
}

export interface HandoffResponse {
  id: string
  session_id: string
  handed_off_by: string
  intent: 'park' | 'escalate'
  source_branch_id: string | null
  snapshot: Record<string, unknown>
  ai_assessment: string | null
  ai_assessment_data: {
    likely_cause: string
    suggested_steps: string[]
    confidence: number
  } | null
  artifacts: Array<{
    name: string
    type: string
    reference: string
  }> | null
  engineer_notes: string | null
  priority: 'normal' | 'elevated'
  claimed_by: string | null
  claimed_at: string | null
  psa_note_pushed: boolean
  notification_sent: boolean
  created_at: string
}

export interface QueueItemResponse {
  handoff_id: string
  session_id: string
  intent: 'park' | 'escalate'
  problem_summary: string | null
  problem_domain: string | null
  priority: 'normal' | 'elevated'
  handed_off_by_name: string | null
  engineer_notes: string | null
  branch_count: number
  created_at: string
  claimed_by: string | null
  claimed_at: string | null
}

// ── Resolution Outputs ──

export type ResolutionOutputType = 'psa_ticket_notes' | 'knowledge_base' | 'client_summary'
export type ResolutionOutputStatus = 'draft' | 'approved' | 'pushed' | 'rejected'

export interface ResolutionOutputResponse {
  id: string
  session_id: string
  output_type: ResolutionOutputType
  generated_content: string
  structured_data: Record<string, unknown> | null
  edited_content: string | null
  status: ResolutionOutputStatus
  pushed_to: string | null
  pushed_at: string | null
  pushed_reference: string | null
  generated_by_model: string
  created_at: string
  updated_at: string
}

export interface AllResolutionOutputsResponse {
  outputs: ResolutionOutputResponse[]
}

export interface ResolutionOutputEditRequest {
  edited_content: string
}

export type PushDestination = 'psa' | 'kb_library' | 'clipboard' | 'email'

export interface ResolutionOutputPushRequest {
  destination: PushDestination
}
