/**
 * The atomic unit — a single message in a chat session.
 *
 * Composed of role + content + optional rich-data slots (attachments,
 * sources, tool calls). Serializable: no Date, no Map.
 */

import type { ChatAttachment, ChatSource } from './attachment';
import type { MessageBlock } from './block';
import type { ChatPersona, ChatRole } from './persona';
import type { ChatToolCall } from './tool-call';

export interface ChatMessage {
  id: string;
  role: ChatRole;
  content: string;
  /** epoch ms — serializable. */
  createdAt: number;
  isStreaming?: boolean;
  isError?: boolean;
  /** Bumps on edit so memo keys invalidate. */
  version?: number;
  /** Per-message persona override (multi-user / multi-bot). Falls back to
   *  `ChatConfig.user` / `ChatConfig.assistant` when absent. */
  sender?: ChatPersona;
  /** Simple status indicator above message ("Searching knowledge base..."). */
  toolActivity?: string;
  toolCalls?: ChatToolCall[];
  attachments?: ChatAttachment[];
  /** Rich tool-component blocks rendered after the message body. */
  blocks?: MessageBlock[];
  sources?: ChatSource[];
  tokensIn?: number;
  tokensOut?: number;
}
