use reqwest::Error as ReqwestError;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum AppError {
    #[error("Configuration error: {0}")]
    Configuration(String),

    #[error("Data parsing error: {0}")]
    DataParsing(#[from] anyhow::Error),

    #[error("Internal error: {0}")]
    Internal(String),

    #[error("Provider not available: {0}")]
    ProviderNotAvailable(String),

    #[error(transparent)]
    Reqwest(#[from] ReqwestError),

    #[error(transparent)]
    Nats(#[from] async_nats::Error),

    #[error(transparent)]
    NatsSubscribe(#[from] async_nats::client::SubscribeError),

    #[error(transparent)]
    NatsUnsubscribe(#[from] async_nats::UnsubscribeError),

    #[error(transparent)]
    NatsPublish(#[from] async_nats::error::Error<async_nats::client::PublishErrorKind>),
}

impl From<config::ConfigError> for AppError {
    fn from(e: config::ConfigError) -> Self {
        AppError::Configuration(e.to_string())
    }
}

pub type Result<T, E = AppError> = std::result::Result<T, E>;
