// Wire shape of the collector's incident read routes (collector/src/incidents/incident-service.ts).
// Mirrored rather than imported: apps/web does not depend on the collector package.

export type IncidentPriority = 'P0' | 'P1' | 'P2' | 'P3'

export type IncidentState = 'filed' | 'dispatching' | 'running' | 'needs-attention' | 'resolved'

export type IncidentScope = 'active' | 'resolved' | 'all'

export interface IncidentCoverage {
  stale: boolean
  detail?: string
}

export interface IncidentDispatch {
  state: IncidentState
  dispatchId: string | null
  cli: string | null
  model: string | null
  wrapperModel: string | null
  reasoningEffort: string | null
  account: string | null
  requestSha256: string | null
  statusRevision: number | null
  startedAt: string | null
  heartbeatAt: string | null
  completedAt: string | null
  exitCode: number | null
  failureClass: string | null
  resultSummary: string | null
}

export interface IncidentActivity {
  id: number
  at: string | null
  comment: string
  username: string
}

export interface Incident {
  id: string
  kanboardTaskId: number
  title: string
  description: string
  priority: IncidentPriority | null
  incidentType: string | null
  dispatchBrief: string | null
  dispatchBriefProvenance: string | null
  state: IncidentState
  active: boolean
  createdAt: string | null
  updatedAt: string | null
  resolvedAt: string | null
  dispatch: IncidentDispatch
  activity: IncidentActivity[]
  coverage: IncidentCoverage
}

export interface IncidentsResponse {
  incidents: Incident[]
  coverage: IncidentCoverage
  page: {
    highWater: number
    nextCursor: number | null
    exhausted: boolean
    order: 'id_desc'
  }
}

export interface ListIncidentsParams {
  scope: IncidentScope
  query?: string
  priority?: IncidentPriority
  limit?: number
  cursor?: number
  highWater?: number
}

export interface FileIncidentRequest {
  requestId: string
  title: string
  description: string
  cli: string
  model: string
  reasoningEffort: string
  account: string
  unsafe: boolean
  priority: IncidentPriority
  incidentType?: string
}

export interface FileIncidentResponse {
  incident: Incident
}

export interface IncidentTypeOption {
  id: string
  title: string
  keywords: string[]
}

export interface IncidentCliOption {
  id: string
  label: string
  models: Array<{ id: string; efforts: string[] }>
  accounts: Array<{ slug: string; label: string; ready: boolean; fixed: boolean }>
  permissionModes: Array<'safe' | 'unsafe'>
}

export interface IncidentOptionsResponse {
  types: IncidentTypeOption[]
  clis: IncidentCliOption[]
}
