// --- Model types ---

export interface OllamaModelDetails {
  family?: string;
  families?: string[];
  format?: string;
  parameter_size?: string;
  quantization_level?: string;
}

export interface OllamaModel {
  name: string;
  model?: string;
  size: number;
  digest: string;
  modified_at: string;
  details?: OllamaModelDetails;
}

export interface OllamaRunningModel {
  name: string;
  model?: string;
  size: number;
  digest: string;
  expires_at: string;
  size_vram: number;
  details?: OllamaModelDetails;
}

// --- Chat types ---

export interface OllamaChatMessage {
  role: 'user' | 'assistant' | 'system';
  content: string;
  images?: string[];
}

export interface OllamaStreamChunk {
  model: string;
  message: { role: string; content: string };
  done: boolean;
  total_duration?: number;
  eval_count?: number;
  eval_duration?: number;
  prompt_eval_count?: number;
  prompt_eval_duration?: number;
  load_duration?: number;
}

// --- Generate types ---

export interface OllamaGenerateChunk {
  model: string;
  response: string;
  done: boolean;
  total_duration?: number;
  eval_count?: number;
  eval_duration?: number;
  prompt_eval_count?: number;
  prompt_eval_duration?: number;
  load_duration?: number;
  context?: number[];
}

// --- Embedding types ---

export interface OllamaEmbeddingResponse {
  model: string;
  embeddings: number[][];
  total_duration?: number;
  load_duration?: number;
  prompt_eval_count?: number;
}

// --- Show types ---

export interface OllamaShowResponse {
  modelfile: string;
  parameters: string;
  template: string;
  details: OllamaModelDetails;
  model_info?: Record<string, unknown>;
}

// --- Pull progress types ---

export interface OllamaPullProgress {
  status: string;
  digest?: string;
  total?: number;
  completed?: number;
}

// --- Version types ---

export interface OllamaVersionResponse {
  version: string;
}

// --- Client options ---

export interface OllamaClientOptions {
  /** Base URL of the Ollama server (e.g. http://localhost:11434) */
  baseUrl: string;
  /** Default request timeout in milliseconds (default: 30000) */
  timeoutMs?: number;
}

export interface OllamaChatOptions {
  model: string;
  messages: OllamaChatMessage[];
  signal?: AbortSignal;
  options?: Record<string, unknown>;
  format?: 'json' | string;
  keep_alive?: string;
}

export interface OllamaGenerateOptions {
  model: string;
  prompt: string;
  signal?: AbortSignal;
  system?: string;
  options?: Record<string, unknown>;
  format?: 'json' | string;
  keep_alive?: string;
  context?: number[];
}

export interface OllamaEmbedOptions {
  model: string;
  input: string | string[];
  options?: Record<string, unknown>;
}
