use serde::Deserialize;

#[derive(Debug, thiserror::Error)]
pub enum EuroMailError {
    #[error("Authentication failed: {0}")]
    Authentication(String),

    #[error("Validation error [{code}]: {message}")]
    Validation { code: String, message: String },

    #[error("Rate limit exceeded: {message}")]
    RateLimit {
        retry_after: Option<u64>,
        message: String,
    },

    #[error("Not found: {0}")]
    NotFound(String),

    #[error("API error [{status}] {code}: {message}")]
    Api {
        status: u16,
        code: String,
        message: String,
    },

    #[error("HTTP error: {0}")]
    Http(#[from] reqwest::Error),
}

#[derive(Deserialize)]
pub(crate) struct ApiErrorBody {
    #[serde(default = "default_code")]
    pub code: String,
    #[serde(default = "default_message")]
    pub message: String,
}

fn default_code() -> String {
    "unknown".to_string()
}

fn default_message() -> String {
    "Unknown error".to_string()
}
