use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum OauthProvider {
    Google,
    GitHub,
    Apple,
    Microsoft,
    GitLab,
    Bitbucket,
}

#[derive(Debug, Clone, Deserialize)]
pub struct OauthProviderInfo {
    pub provider: OauthProvider,
    pub label: String,
    pub scopes: Vec<String>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct OauthProvidersResponse {
    pub product: String,
    pub providers: Vec<OauthProviderInfo>,
}

#[derive(Debug, Clone, Serialize)]
pub struct OauthExchangePayload<'a> {
    pub code: &'a str,
    pub code_verifier: &'a str,
}

#[derive(Debug, Clone, Deserialize)]
pub struct OauthExchangeCustomer {
    pub id: String,
    pub email: String,
    #[serde(default)]
    pub name: Option<String>,
    pub product_id: String,
}

#[derive(Debug, Clone, Deserialize)]
pub struct OauthExchangeEntitlement {
    #[serde(default)]
    pub plan_key: Option<String>,
    pub source: String,
    #[serde(default)]
    pub ends_at: Option<String>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct OauthExchangeResponse {
    pub access_token: String,
    pub token_type: String,
    pub customer: OauthExchangeCustomer,
    #[serde(default)]
    pub entitlement: Option<OauthExchangeEntitlement>,
    #[serde(default)]
    pub requires_plan_selection: bool,
}
