// frontend/src/types/agent.ts
// #region Types.Agent [C:1] [TYPE Module] [SEMANTICS agent,types,dto]
// @BRIEF TypeScript DTOs for Gradio Agent Chat — must match backend/src/schemas/agent.py exactly.

export interface ConversationItem {
  id: string;
  title: string;
  updated_at: string;
  message_count: number;
}

export interface ConversationListResponse {
  items: ConversationItem[];
  has_next: boolean;
  active_total: number;
  archived_total: number;
}

export interface ToolCall {
  tool: string;
  input: Record<string, unknown>;
  output?: Record<string, unknown>;
  error?: string;
  status: "executing" | "completed" | "failed";
}

export interface AttachmentMeta {
  name: string;
  type: "pdf" | "xlsx" | "json" | "csv" | "txt" | "png" | "jpeg";
  size: number;
  preview_url?: string;
}

export interface StreamMetadata {
  type?: "stream_token" | "tool_start" | "tool_end" | "tool_error"
       | "confirm_required" | "confirm_resolved" | "error";
  token?: string;
  tool?: string;
  input?: Record<string, unknown>;
  output?: Record<string, unknown>;
  error?: string;
  prompt?: string;
  thread_id?: string;
  result?: "confirmed" | "denied";
  code?: string;
  detail?: string;
}

export interface MessageItem {
  id: string;
  conversation_id: string;
  role: "user" | "assistant" | "tool" | "system";
  text: string | null;
  metadata?: StreamMetadata;
  state?: string;
  task_id?: string;
  tool_calls: ToolCall[] | null;
  attachments: AttachmentMeta[] | null;
  created_at: string;
}

export interface HistoryResponse {
  items: MessageItem[];
  has_next: boolean;
  conversation_id: string | null;
}

export interface DeleteResponse {
  deleted: boolean;
}
// #endregion Types.Agent
