use serde::{Deserialize, Serialize};

/// Response for a successful login, containing the JWT.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AuthResponse {
    pub token: String,
}

/// Response after successfully sending a chat message.
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
pub struct ChatSendMessageResponse {
    pub status: String,
    pub message: String,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct User {
    pub authority: String,
    pub username: String,
}

// Notifications

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct ChatNotification {
    pub authority: String,
    pub username: String,
    pub text: String,
    pub id: u64,
    pub ts: i64,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct ResetNotification {
    pub block_id: u64,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub enum Notification {
    Chat(ChatNotification),
    Reset(ResetNotification),
}

impl Notification {
    pub fn id(&self) -> String {
        match self {
            Notification::Chat(chat) => chat.id.to_string(),
            Notification::Reset(reset) => reset.block_id.to_string(),
        }
    }
}
