export interface TerminalLine {
  id: string;
  type: "user" | "assistant" | "system" | "tool" | "error";
  content: string;
  timestamp: Date;
  toolName?: string;
}

export interface SystemInitMessage {
  type: "system";
  subtype: "init";
  session_id: string;
  cwd: string;
  tools: string[];
  mcp_servers?: string[];
  model?: string;
}

export interface SystemCompactMessage {
  type: "system";
  subtype: "compact_boundary";
}

export type SystemMessage = SystemInitMessage | SystemCompactMessage;

export interface TextContentBlock {
  type: "text";
  text: string;
}

export interface ThinkingContentBlock {
  type: "thinking";
  thinking: string;
}

export interface ToolUseContentBlock {
  type: "tool_use";
  id: string;
  name: string;
  input: Record<string, unknown>;
}

export interface ToolResultContentBlock {
  type: "tool_result";
  tool_use_id: string;
  content: string;
  is_error?: boolean;
}

export type ContentBlock =
  | TextContentBlock
  | ThinkingContentBlock
  | ToolUseContentBlock
  | ToolResultContentBlock;

export interface AssistantMessage {
  type: "assistant";
  message: {
    content: ContentBlock[];
    model?: string;
    stop_reason?: string;
  };
  parent_tool_use_id?: string;
}

export interface UserMessage {
  type: "user";
  message: {
    content: ContentBlock[];
  };
}

export interface StreamEvent {
  type: "stream_event";
  event: {
    type: string;
    index?: number;
    content_block?: ContentBlock;
    delta?: {
      type: string;
      text?: string;
      thinking?: string;
    };
  };
}

export interface PermissionDenial {
  tool_name: string;
  tool_use_id: string;
  tool_input: Record<string, unknown>;
}

export interface ResultMessage {
  type: "result";
  subtype: "success" | "error_max_turns" | "error_tool" | "error_api" | "error_unknown";
  result?: string;
  duration_ms?: number;
  num_turns?: number;
  total_cost_usd?: number;
  usage?: {
    input_tokens: number;
    output_tokens: number;
  };
  permission_denials?: PermissionDenial[];
}

export type ClaudeStreamMessage =
  | SystemMessage
  | AssistantMessage
  | UserMessage
  | StreamEvent
  | ResultMessage;

export interface PermissionRequest {
  id: string;
  tool: string;
  description: string;
  input: Record<string, unknown>;
}

export interface PermissionPromptEvent {
  id: string;
  tool_name: string;
  tool_input: Record<string, unknown>;
  description: string;
  conversation_id?: string;
}

export interface QuestionOption {
  label: string;
  description?: string;
}

export interface UserQuestionEvent {
  id: string;
  question: string;
  header?: string;
  options: QuestionOption[];
  multi_select: boolean;
  conversation_id?: string;
}

export type ConnectionStatus = "disconnected" | "connecting" | "connected" | "error";

export interface Attachment {
  id: string;
  filename: string;
  path: string;
  size: number;
  type: "image" | "document" | "other";
  mimeType?: string;
  previewUrl?: string; // For images, a data URL or object URL for preview
}

export interface UpdateInfo {
  current_version: string;
  latest_version: string;
  has_update: boolean;
  release_url: string;
  release_notes?: string;
}
