use crate::connection::ConnectionId;
use nostr_rs_types::{Request, Response};

#[derive(Debug, thiserror::Error)]
/// Relayer error
pub enum Error {
    /// Database/ Storage error
    #[error("Internal/DB: {0}")]
    Storage(#[from] nostr_rs_storage_base::Error),

    /// Web-socket related errors
    #[error("WebSocket error: {0}")]
    WebSocket(#[from] tokio_tungstenite::tungstenite::Error),

    /// Serialization related errors
    #[error("Serialization: {0}")]
    Serde(#[from] serde_json::Error),

    /// Tokio channel's error
    #[error("TrySendError: {0}")]
    TrySendError(#[from] Box<tokio::sync::mpsc::error::TrySendError<Response>>),

    /// Tokio channel's error
    #[error("LocalTrySendError: {0}")]
    LocalSendError(#[from] Box<tokio::sync::mpsc::error::SendError<(ConnectionId, Request)>>),

    /// Client related errors
    #[error("Nostr client error: {0}")]
    Client(#[from] nostr_rs_client::Error),

    /// Unknown connections
    #[error("Unknown connection: {0}")]
    UnknownConnection(u128),

    /// The relayer is already splitten
    #[error("Relayer already splitten")]
    AlreadySplitted,
}
