use thiserror::Error;

#[derive(Debug, Error)]
pub enum SunscreenError {
    #[error("missing required environment variable: {0}")]
    MissingEnvVar(String),

    #[error("invalid request: {0}")]
    InvalidRequest(String),

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

    #[error("address not found")]
    NotFound,

    #[error("data source fetch failed: {0}")]
    DataSourceFetch(String),

    #[error("database error: {0}")]
    Database(#[from] sqlx::Error),

    #[error("migration error: {0}")]
    Migration(#[from] sqlx::migrate::MigrateError),

    #[error("json error: {0}")]
    Json(#[from] serde_json::Error),

    #[error("http client error: {0}")]
    HttpClient(#[from] reqwest::Error),
}

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