export type { RequestStoryEvent, RequestStoryV1 } from '@overdeck/report-contract'

export type RequestState = 'asked' | 'in_flight' | 'blocked_needs_owner' | 'orphaned' | 'shipped' | 'canceled'
export type RequestOrigin = 'owner' | 'agent-incident' | 'agent-judgement'

export interface RequestReceiptMeta {
  worker?: string
  host?: string
  session_id?: string
}

/** Registry-backed activity. Omitted until the live-status registry detail projection is available. */
export interface RequestReceipt {
  id: string
  request_id: string
  at: string
  kind: 'claimed' | 'progress' | 'landed' | 'deployed' | 'failed' | 'worker-lost' | 'queue-event' | string
  line: string
  meta?: RequestReceiptMeta
}

export interface RequestTransition {
  id: string
  request_id: string
  at: string
  from_state: RequestState
  to_state: RequestState
  actor: string
  reason: string | null
}

export interface RequestRow {
  id: string
  title: string
  project: string
  state: RequestState
  priority: string
  origin: RequestOrigin
  asked_at: string
  original_body?: string | null
  original_body_format?: 'plain_text' | 'markdown' | null
  intake_source?: string | null
  intake_source_event_id?: string | null
  updated_at: string
  worker: string | null
  detail: string | null
  proof_url: string | null
  plan_ref: string | null
  factory_run_id?: string | null
  session_name?: string | null
  session_id?: string | null
  /** Present only when the collector can authoritatively project registry receipts. */
  receipt_trail?: RequestReceipt[]
  /** Present only when the collector can authoritatively project lifecycle transitions. */
  transition_trail?: RequestTransition[]
}

export interface RequestsResponse {
  requests: RequestRow[]
}
