use oauth2::basic::BasicErrorResponseType;
use oauth2::{HttpClientError, RequestTokenError, StandardErrorResponse};
use thiserror::Error;
#[derive(Error, Debug)]
pub enum OAuthError {
#[error(
"OAuth2 not configured for Client\n\
\n\
To fix this configure your Client with the client ID, client secret,\n\
and callback URL from https://developers.eveonline.com/applications\n\
\n\
See this example: https://github.com/hyziri/eve_esi/blob/main/examples/sso.rs"
)]
OAuth2NotConfigured,
#[error("JWT key refresh timeout: {0}")]
JwtKeyRefreshTimeout(String),
#[error("JWT key refresh failure: {0}")]
JwtKeyRefreshFailure(String),
#[error("JWT key cache refresh cooldown still active: {0}")]
JwtKeyRefreshCooldown(String),
#[error("OAuth2 token error: {0:?}")]
RequestTokenError(
RequestTokenError<
HttpClientError<reqwest::Error>,
StandardErrorResponse<BasicErrorResponseType>,
>,
),
#[error("Validate token error: {0:?}")]
ValidateTokenError(jsonwebtoken::errors::Error),
#[error("No valid token key for validation found in cache: {0:?}")]
NoValidKeyFound(String),
#[error("Access token is expired\n
\n
See instructions on how to refresh an expired token here: <https://docs.rs/eve_esi/latest/eve_esi/oauth2/index.html>")]
AccessTokenExpired(),
#[error(
"Missing required scopes for access token\n
\n\
Update your application at <https://developers.eveonline.com/applications>
to include the missing scopes:\n
{0:?}"
)]
AccessTokenMissingScopes(Vec<String>),
#[error("Failed to parse character ID from EveJwtClaims due to error: {0:?}")]
CharacterIdParseError(String),
}