export type DebugEmlErrorCode =
  | 'REQUEST_FIELD_REQUIRED'
  | 'EML_FILE_REQUIRED'
  | 'EML_FILE_TOO_LARGE'
  | 'INVALID_FILE_TYPE'
  | 'DEBUG_UPLOAD_KEY_INVALID'
  | 'EML_PARSE_FAILED'
  | 'OSS_UPLOAD_FAILED'
  | 'SUPERAGENT_OPEN_API_FAILED'
  | 'DEBUG_EML_RUN_FAILED'
  | string

export interface DebugEmlUploadInput {
  hotelId?: string | null
  debugUploadKey: string
  file: File
  runLabel?: string
}

export interface DebugEmlSuperAgentRunResult {
  debug_run_id: string
  source_message_id: string | null
  source_provider: string | null
  external_message_id: string | null
  external_conversation_id: string | null
  original_eml_oss_url: string | null
  original_eml_sha256: string | null
  uploaded_media: DebugEmlUploadedMediaResult[]
  html_body_with_oss_urls: string | null
  html_body_sanitized: string | null
  html_sanitize_required: boolean | null
  html_render_mode: 'SANITIZED_HTML' | 'TEXT_ONLY' | string | null
  agentbus_like_payload: Record<string, unknown> | null
  superagent_session_id: string | null
  superagent_run_id: string | null
  superagent_raw_answer: string | null
  superagent_parsed_json: unknown | null
  superagent_trace_events: DebugEmlSuperAgentTraceEvent[]
  warnings: string[]
  status: string | null
}

export interface DebugEmlSuperAgentTraceEvent {
  event: string | null
  run_id: string | null
  message_id: string | null
  tool_call_id: string | null
  tool_name: string | null
  text: string | null
  input_summary: string | null
  output_summary: string | null
  status: string | null
  ts: string | null
}

export interface DebugEmlStageEvent {
  debug_run_id: string | null
  status: string | null
  safe_summary: string | null
}

export interface DebugEmlUploadedMediaResult {
  media_type: string | null
  file_name: string | null
  content_type: string | null
  size_bytes: number | null
  external_url: string | null
  external_media_id: string | null
  object_key: string | null
}

export interface DebugEmlErrorResponse {
  error_code?: DebugEmlErrorCode
  message?: string
}

export interface DebugEmlStreamHandlers {
  onStage?: (stage: DebugEmlStageEvent) => void
  onTrace?: (trace: DebugEmlSuperAgentTraceEvent) => void
  onResult?: (result: DebugEmlSuperAgentRunResult) => void
}
