/// Redis operation errors.
#[derive(Debug, thiserror::Error)]
pub enum RedisError {
    /// Failed to obtain a connection from the pool.
    #[error("Redis pool error: {0}")]
    Pool(#[from] deadpool_redis::PoolError),
    /// Redis command failed.
    #[error("Redis error: {0}")]
    Redis(#[from] redis::RedisError),
    /// JSON serialization/deserialization failed.
    #[error("Serialization error: {0}")]
    Serialization(#[from] serde_json::Error),
    /// Invalid pool configuration.
    #[error("Pool config error: {0}")]
    PoolConfig(#[from] deadpool_redis::ConfigError),
    /// Failed to build connection pool.
    #[error("Pool build error: {0}")]
    PoolBuild(#[from] deadpool_redis::BuildError),
    /// Expected data was not found in Redis.
    #[error("Not found: {0}")]
    NotFound(String),
    /// Arithmetic overflow during position computation.
    #[error("Math overflow")]
    MathOverflow,
}

impl From<pyra_margin::MathError> for RedisError {
    fn from(_: pyra_margin::MathError) -> Self {
        Self::MathOverflow
    }
}

pub type RedisResult<T> = Result<T, RedisError>;
