use serde::{Deserialize, Serialize};
use solana_sdk::{pubkey::Pubkey, signature::Signature};

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct SwapInfo {
    pub signature: Signature,
    pub amount: i64,
    pub quote: i64,
    pub price: f64,
    pub timestamp: i64,
    pub authority: String,
    pub direction: i64,
    pub block_id: u64,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct MinerInfo {
    pub authority: Pubkey,
    pub amount: i64,
    pub block_id: u64,
}

/// 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,
}

// Notifications

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

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

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

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

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