export type Attachment =
  | { type: 'webpage'; url: string; title: string; content: string; attachmentId: string; loading?: boolean }
  | { type: 'image'; filename: string; dataUrl: string; attachmentId: string; loading?: boolean };

export type MessageCost = {
  inputTokens: number;
  outputTokens: number;
  totalUSD: number;
};

export type ModelOption = {
  id: string;
  name: string;
  provider: string;
  contextWindow: number;
  maxTokens: number;
  reasoning?: boolean;
  images?: boolean;
};

export type ChatMessage =
  | { role: 'user'; text: string; images?: { filename: string; dataUrl: string }[] }
  | { role: 'assistant'; id?: string; text: string }
  | { role: 'system'; text: string }
  | {
      role: 'tool';
      toolName: string;
      toolInput: Record<string, unknown>;
      toolCallId: string;
      output?: string;
      isError?: boolean;
    }
  | { role: 'result'; cost: MessageCost }
  | { role: 'error'; text: string };

export type TaskInfo = {
  taskName: string;
  taskDirName: string;
  entryName: string;
  entryType: 'file' | 'directory';
};

export type ServerMessage =
  | { type: 'session:init'; sessionId: string; model: string; cwd: string; context?: string; contextId?: string }
  | { type: 'assistant:text'; text: string }
  | { type: 'assistant:delta'; text: string }
  | { type: 'tool:start'; toolCallId: string; toolName: string; toolInput: Record<string, unknown> }
  | { type: 'tool:result'; toolCallId: string; output: string; isError: boolean }
  | { type: 'result'; sessionId: string; cost: MessageCost }
  | { type: 'sync:messages'; sessionId: string; messages: Message[]; isGenerating: boolean; streamingText: string }
  | { type: 'error'; message: string; errorCode?: string }
  | { type: 'stopped' }
  | { type: 'disconnected' }
  | { type: 'task:started'; taskId: string; description: string; taskType?: string }
  | { type: 'task:notification'; taskId: string; status: 'completed' | 'failed' | 'stopped'; summary: string };

export type Message = {
  id: string;
  timestamp: number;
  role: 'user' | 'assistant' | 'tool';
  text?: string;
  model?: string;
  cost?: MessageCost;
  toolCallId?: string;
  toolName?: string;
  toolInput?: Record<string, unknown>;
  output?: string;
  isError?: boolean;
};

export type SlashCommand = {
  command: string;
  description?: string;
  execute: (args: string, sessionId: string) => Promise<{ success: boolean; feedback: string }>;
};
