use rocket::serde::{Deserialize, Serialize};
use sqlx::FromRow;
use chrono::{DateTime, Utc};
use uuid::Uuid;

/// ---------- Rocket routes ----------
#[derive(Debug, Serialize, Deserialize, Clone, FromRow)]
pub struct ChatMsg {
    pub id: Uuid,
    pub display_name: Option<String>,
    pub user_id: i64,
    pub text: String,
    pub timestamp: DateTime<Utc>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", content = "data")]
pub enum ChatEvent {
    SendMessage(ChatMsg),

    /// for when a user explicitly edits a message
    EditMessage { id: Uuid, msg: ChatMsg },

    /// used for streaming content to a message
    /// will not show up as edited
    MessageAppendContent{ id: Uuid, content: String }
}