export interface AttachmentData {
  filename?: string;
  size?: number;
  mime_type?: string;
  download_url?: string;
  type?: string;
}

export interface UIButtonData {
  label: string;
  action: string;
  payload?: Record<string, unknown>;
  style?: string;
}

export interface ChatMessage {
  id: string;
  chat_id: string;
  text: string;
  from: "user" | "agent";
  timestamp: number;
  parse_mode?: string;
  attachments?: AttachmentData[];
  buttons?: UIButtonData[];
}

export type ServerMessage =
  | { type: "connected"; user_id: string; session_token: string }
  | { type: "history"; chats: Record<string, ChatMessage[]>; chat_names?: Record<string, string>; archived?: string[] }
  | { type: "message"; chat_id?: string; text: string; parse_mode?: string; attachments?: AttachmentData[]; buttons?: UIButtonData[] }
  | { type: "ui"; chat_id?: string; text: string; buttons?: UIButtonData[] }
  | { type: "typing"; chat_id?: string; is_typing: boolean }
  | { type: "notification"; chat_id?: string; text: string; level: string }
  | { type: "chat_name"; chat_id: string; name: string }
  | { type: "chat_archived"; chat_id: string }
  | { type: "chat_unarchived"; chat_id: string }
  | { type: "chat_new"; chat_id: string }
  | { type: "error"; text: string }
  | { type: "sessions"; sessions: { name: string; created_at: string }[] };

export type ClientMessage =
  | { type: "auth"; session_token?: string }
  | { type: "message"; user_id: string; chat_id: string; text: string }
  | { type: "command"; user_id: string; chat_id: string; command: string; args: string[] }
  | { type: "callback"; user_id: string; chat_id: string; action: string; payload?: Record<string, unknown> };
