#[derive(thiserror::Error, Debug)]
pub enum GoogleError {
    #[error("Google API error: {status} {message}")]
    Api { status: u16, message: String },

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

    #[error("Token refresh failed: {0}")]
    TokenRefresh(String),

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

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

impl GoogleError {
    pub fn api(status: u16, message: impl Into<String>) -> Self {
        Self::Api {
            status,
            message: message.into(),
        }
    }

    pub fn auth(message: impl Into<String>) -> Self {
        Self::Auth(message.into())
    }

    pub fn token_refresh(message: impl Into<String>) -> Self {
        Self::TokenRefresh(message.into())
    }
}

/// Google API error response body
#[derive(serde::Deserialize, Debug)]
pub(crate) struct GoogleApiErrorBody {
    pub error: GoogleApiErrorDetail,
}

#[derive(serde::Deserialize, Debug)]
pub(crate) struct GoogleApiErrorDetail {
    pub code: u16,
    pub message: String,
}
