import type { AttemptRecord } from '../components/plans/attempt-record'

export type HarnessJson = null | boolean | number | string | HarnessJson[] | { [key: string]: HarnessJson }

export type HarnessCapabilities = Record<string, boolean | string | number | null>

export interface HarnessEvent {
  id: string
  source: string
  kind: string
  ts: string
  taskId?: string | null
  attemptId?: string | null
  /** Factory phase identity, present only when the producer explicitly records it. */
  phaseId?: string | null
  seq?: number | null
  payload: Record<string, HarnessJson>
}

export type HarnessDecisionOption = string | {
  value: string
  meaning?: string
  label?: string
  recommended?: boolean
}

export interface HarnessDecision {
  id: string
  task: string | null
  summary: string | null
  options: HarnessDecisionOption[]
  requestedAt: string | null
  status?: string
  category?: HarnessJson
  needs?: HarnessJson
  why?: string
  blast_radius?: HarnessJson
}

export interface HarnessDecisionsResponse {
  decisions: HarnessDecision[]
  capabilities: HarnessCapabilities
}

export interface HarnessRateLimit {
  provider: string
  state: string
  resumeAt?: string | null
  waitMs?: number | null
  wrapper?: string
  task?: string
}

export interface HarnessRunDetailResponse {
  run: { ratelimits?: Record<string, HarnessRateLimit> }
}

export interface HarnessEventsResponse {
  events: HarnessEvent[]
  nextSince: string
  capabilities: HarnessCapabilities
  hasMore?: boolean
}

export interface HarnessConfigField {
  value?: HarnessJson
  source: string
  immutable: boolean
  mutationClass: 'launch' | 'mid-run' | 'global'
  isSecret?: boolean
  redacted?: boolean
}

export interface HarnessRunConfigResponse {
  revision: string
  fields: Record<string, HarnessConfigField>
}

export interface HarnessEffectivePlanResponse {
  runId: string
  revision: string
  planHash: string
  tasks: HarnessJson[]
  meta: Record<string, HarnessJson> | null
}

export interface HarnessAttemptsResponse {
  attempts: AttemptRecord[]
}
