//! Chat message aggregate stored in `athena.chat_messages`.

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_json::Value;

use crate::ids::{MessageId, RoomId, UserId};

/// Durable chat message with optional structured body and reply link.
///
/// Maps to `athena.chat_messages`; [`crate::repo::traits::ChatRepository`] assigns `room_seq`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChatMessage {
    pub id: MessageId,
    pub room_id: RoomId,
    /// Monotonic sequence within the room.
    pub room_seq: i64,
    pub sender_id: UserId,
    /// Client-supplied idempotency key for send retries.
    pub client_message_id: Option<String>,
    pub body_text: Option<String>,
    pub body_json: Option<Value>,
    pub reply_to_message_id: Option<MessageId>,
    pub created_at: DateTime<Utc>,
    pub edited_at: Option<DateTime<Utc>>,
    /// Set when the message is soft-deleted.
    pub deleted_at: Option<DateTime<Utc>>,
    pub metadata_json: Option<Value>,
}
