import type { ReviewStatus } from './enums'

export const AIOutputType = {
  NEED_PARSE:           'NEED_PARSE',
  FOLLOW_UP_QUESTIONS:  'FOLLOW_UP_QUESTIONS',
  MATCH_EXPLANATION:    'MATCH_EXPLANATION',
  COMPARE_SUMMARY:      'COMPARE_SUMMARY',
  DECISION_BRIEF:       'DECISION_BRIEF',
  DATA_QUALITY_SUMMARY: 'DATA_QUALITY_SUMMARY',
} as const
export type AIOutputType = typeof AIOutputType[keyof typeof AIOutputType]

export const AIErrorType = {
  SCHEMA_VALIDATION: 'SCHEMA_VALIDATION',
  PROVIDER_TIMEOUT:  'PROVIDER_TIMEOUT',
  INVALID_JSON:      'INVALID_JSON',
  EMPTY_RESPONSE:    'EMPTY_RESPONSE',
  RATE_LIMIT:        'RATE_LIMIT',
} as const
export type AIErrorType = typeof AIErrorType[keyof typeof AIErrorType]

export interface AIOutputError {
  type: AIErrorType
  message: string
  recoverable: boolean
}

export interface AIOutput {
  id: string
  type: AIOutputType
  provider: string
  model: string
  promptVersion: string
  schemaVersion: string
  inputHash: string
  outputPreview: string
  createdAt: string
  latencyMs?: number
  costEstimate?: number
  reviewStatus: ReviewStatus
  relatedEntityType: string
  relatedEntityId: string
  error?: AIOutputError
}
