export interface OllamaModel {
  name: string;
  size: number;
  digest: string;
  modified_at: string;
  details?: {
    family?: string;
    parameter_size?: string;
    quantization_level?: string;
  };
}

export interface RunningModel {
  name: string;
  size: number;
  digest: string;
  expires_at: string;
  size_vram: number;
}

export interface OllamaData {
  status: string;
  url: string;
  models: OllamaModel[];
  running: RunningModel[];
  totalModels: number;
  totalSize: number;
  runningCount: number;
  version?: string;
}

export interface WhisperModel {
  name: string;
  size: number;
  path: string;
}

export interface WhisperData {
  installed: boolean;
  version: string;
  binaries: string[];
  models: WhisperModel[];
  modelsDir: string;
}

export interface SystemData {
  chip: string;
  gpu: string;
  memory: { total: number; appMemory: number; cached: number; free: number; pressure: string };
  disk: { total: number; used: number; free: number };
  ollamaDiskUsage: number;
  cpuCores: number;
  uptime: number;
  platform: string;
  arch: string;
  nodeVersion: string;
  brewPackages: Array<{ name: string; version: string }>;
}

export interface Toast {
  id: number;
  message: string;
  type: 'success' | 'error' | 'info';
}

export interface PullProgress {
  status: string;
  completed: number;
  total: number;
}

export interface StreamMetrics {
  tokensPerSec: number;
  totalTokens: number;
  durationMs: number;
}

// --- v4 Workspace Types ---

export interface Conversation {
  id: string;
  title: string;
  model: string;
  agentId?: string;
  projectId?: string;
  systemPrompt?: string;
  messageCount: number;
  createdAt: number;
  updatedAt: number;
  pinned: boolean;
  archived: boolean;
  metadata: {
    totalTokens: number;
    totalPrompts: number;
    avgTokPerSec: number;
    models: string[];
  };
}

export interface Message {
  id: string;
  conversationId: string;
  role: 'user' | 'assistant' | 'system';
  content: string;
  model?: string;
  timestamp: number;
  attachments?: Attachment[];
  metrics?: {
    tokensPerSec: number;
    totalTokens: number;
    promptTokens: number;
    durationMs: number;
  };
  rating?: 'up' | 'down';
  parentId?: string;
  branchIndex?: number;
}

export interface Attachment {
  type: 'image' | 'file' | 'audio' | 'url';
  name: string;
  data: string;
  mimeType?: string;
  size?: number;
  language?: string;
}

export interface Agent {
  id: string;
  name: string;
  icon: string;
  description: string;
  model: string;
  systemPrompt: string;
  temperature?: number;
  tools: AgentTool[];
  welcomeMessage?: string;
  examplePrompts: string[];
  constraints?: string[];
  responseFormat?: 'markdown' | 'json' | 'code' | 'plain';
  builtin: boolean;
  conversationCount: number;
  createdAt: number;
}

export type AgentTool = 'file_read' | 'vision' | 'voice_input';

export interface QuickAction {
  id: string;
  name: string;
  icon: string;
  category: 'code' | 'writing' | 'analysis' | 'creative' | 'devops' | 'custom';
  description: string;
  modelHint: string;
  systemPrompt: string;
  userTemplate: string;
  builtin: boolean;
  hotkey?: string;
  usageCount: number;
  lastUsed?: number;
}

export interface ModelDefaults {
  fast: string;
  coding: string;
  reasoning: string;
  chat: string;
  vision: string;
}

export interface Project {
  id: string;
  name: string;
  icon: string;
  description?: string;
  defaultModel?: string;
  defaultAgent?: string;
  systemContext?: string;
  conversationIds: string[];
  pinned: boolean;
  createdAt: number;
}

export interface ScheduledTask {
  id: string;
  name: string;
  schedule: string;
  scheduleHuman: string;
  model: string;
  prompt: string;
  inputSource?:
    | { type: 'static' }
    | { type: 'file'; path: string }
    | { type: 'command'; command: string }
    | { type: 'clipboard' };
  outputAction?:
    | { type: 'conversation' }
    | { type: 'clipboard' }
    | { type: 'file'; path: string }
    | { type: 'notification' };
  enabled: boolean;
  lastRun?: number;
  runHistory: Array<{ timestamp: number; durationMs: number; success: boolean; result: string }>;
  createdAt: number;
}

export interface Orchestration {
  id: string;
  name: string;
  mode: 'chain' | 'race' | 'vote';
  steps: OrchestrationStep[];
  synthesizer?: string;
  description?: string;
}

export interface OrchestrationStep {
  model: string;
  systemPrompt?: string;
  transformInput?: string;
}
