//! Chat room aggregate stored in `athena.chat_rooms`.

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

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

/// Durable chat room scoped to an organization.
///
/// Maps to `athena.chat_rooms` and backs [`crate::repo::traits::ChatRepository`] room commits.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Room {
    /// Room primary key.
    pub id: RoomId,
    /// Tenant that owns the room.
    pub organization_id: OrganizationId,
    /// Room kind: `dm`, `group`, or `channel`.
    pub kind: String,
    /// Display title; optional for direct messages.
    pub title: Option<String>,
    /// User that created the room.
    pub created_by: UserId,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
    /// Set when the room is archived; `None` while active.
    pub archived_at: Option<DateTime<Utc>>,
    /// Latest message id for list sorting and previews.
    pub last_message_id: Option<uuid::Uuid>,
    /// Monotonic per-room message sequence counter.
    pub last_message_seq: i64,
    pub last_message_at: Option<DateTime<Utc>>,
    /// Optimistic concurrency version bumped on room or membership changes.
    pub version: i64,
}
