import type { HarnessSelection } from './contracts.js';

export const HARNESS_ERROR_CODES = [
  'auth_required',
  'selection_invalid',
  'catalog_unavailable',
  'catalog_stale',
  'model_unavailable',
  'no_viable_provider',
  'session_create_failed',
  'session_not_found',
  'resume_conflict',
  'session_busy',
  'auth_bundle_concurrency_unverified',
  'adapter_unavailable',
  'sandbox_unavailable',
  'rpc_version_unsupported',
  'rpc_protocol_error',
  'process_exited',
  'outcome_unknown',
  'interaction_unsupported',
  'aborted',
] as const satisfies readonly string[];

export type HarnessErrorCode = (typeof HARNESS_ERROR_CODES)[number];

export interface HarnessErrorDto<Code extends HarnessErrorCode = HarnessErrorCode> {
  readonly code: Code;
  /** Safe for browser and operator-facing surfaces. */
  readonly message: string;
  readonly retryable: boolean;
  readonly correlationId: string;
  /** The requested selection; errors never report a substituted effective selection. */
  readonly selection: HarnessSelection;
}

/** Closed discriminated union over every stable harness error code. */
export type HarnessError = {
  readonly [Code in HarnessErrorCode]: HarnessErrorDto<Code>;
}[HarnessErrorCode];
