export interface GenerationTiming {
  total_ms: number;
  intent_ms: number | null;
  ttft_ms: number | null;
  generation_ms: number | null;
  tools: Array<{ name: string; ms: number }>;
}

export interface ToolCallRecord {
  function: string;
  arguments: Record<string, unknown>;
  result: { success: boolean; type?: string; data?: Record<string, unknown>; error?: string; suggested_tags?: string[]; requires_confirmation?: boolean; similar_note?: { id: number; title: string } };
  status: "running" | "success" | "error" | "declined";
}

export interface ToolPendingRecord {
  function: string;
  arguments: Record<string, unknown>;
  label?: string;
}

export interface Message {
  id: number;
  conversation_id: number;
  role: "system" | "user" | "assistant";
  content: string;
  status?: "complete" | "generating" | "error";
  context_note_id: number | null;
  context_note_title?: string | null;
  tool_calls?: ToolCallRecord[] | null;
  metadata?: Record<string, unknown> | null;
  created_at: string;
  timing?: GenerationTiming;
  thinking?: string;
}

export interface SendMessageResponse {
  assistant_message_id: number;
  status: string;
}

export interface Conversation {
  id: number;
  title: string;
  model: string;
  message_count: number;
  rag_project_id: number | null;
  created_at: string;
  updated_at: string;
}

export interface ConversationDetail extends Conversation {
  messages: Message[];
}

export interface ContextMeta {
  context_note_id: number | null;
  context_note_title: string | null;
  auto_notes: { id: number; title: string; score?: number | null; auto_injected?: boolean }[];
  auto_injected_notes?: { id: number; title: string; score?: number | null }[];
}

export interface OllamaStatus {
  ollama: "available" | "unavailable";
  model: "loaded" | "cold" | "not_found";
  default_model: string;
}
