use std::fmt;

#[derive(Debug)]
pub enum HeliosError {
    /// WebSocket protocol error
    Protocol(String),
    /// JSON serialization/deserialization error
    Serialization(String),
    /// Session not found
    SessionNotFound(String),
    /// Request timed out waiting for client response
    Timeout(String),
    /// Generic internal error
    Internal(String),
}

impl fmt::Display for HeliosError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            HeliosError::Protocol(msg) => write!(f, "Protocol error: {msg}"),
            HeliosError::Serialization(msg) => write!(f, "Serialization error: {msg}"),
            HeliosError::SessionNotFound(id) => write!(f, "Session not found: {id}"),
            HeliosError::Timeout(msg) => write!(f, "Request timed out: {msg}"),
            HeliosError::Internal(msg) => write!(f, "Internal error: {msg}"),
        }
    }
}

impl std::error::Error for HeliosError {}

impl From<serde_json::Error> for HeliosError {
    fn from(e: serde_json::Error) -> Self {
        HeliosError::Serialization(e.to_string())
    }
}
