use std::fmt::Display;
#[derive(Clone, Debug, PartialEq, Hash, Eq)]
pub enum ProviderId {
Password,
Apple,
AppleGameCenter,
Facebook,
GitHub,
Google,
GooglePlayGames,
LinkedIn,
Microsoft,
Twitter,
Yahoo,
Unknown(String),
}
impl Display for ProviderId {
fn fmt(
&self,
f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
match self {
| ProviderId::Password => write!(f, "password"),
| ProviderId::Apple => write!(f, "apple.com"),
| ProviderId::AppleGameCenter => write!(f, "gc.apple.com"),
| ProviderId::Facebook => write!(f, "facebook.com"),
| ProviderId::GitHub => write!(f, "github.com"),
| ProviderId::Google => write!(f, "google.com"),
| ProviderId::GooglePlayGames => write!(f, "playgames.google.com"),
| ProviderId::LinkedIn => write!(f, "linkedin.com"),
| ProviderId::Microsoft => write!(f, "microsoft.com"),
| ProviderId::Twitter => write!(f, "twitter.com"),
| ProviderId::Yahoo => write!(f, "yahoo.com"),
| ProviderId::Unknown(string) => write!(f, "{}", string),
}
}
}
impl ProviderId {
pub fn format(&self) -> String {
match self {
| ProviderId::Password => "password".to_string(),
| ProviderId::Apple => "apple.com".to_string(),
| ProviderId::AppleGameCenter => "gc.apple.com".to_string(),
| ProviderId::Facebook => "facebook.com".to_string(),
| ProviderId::GitHub => "github.com".to_string(),
| ProviderId::Google => "google.com".to_string(),
| ProviderId::GooglePlayGames => "playgames.google.com".to_string(),
| ProviderId::LinkedIn => "linkedin.com".to_string(),
| ProviderId::Microsoft => "microsoft.com".to_string(),
| ProviderId::Twitter => "twitter.com".to_string(),
| ProviderId::Yahoo => "yahoo.com".to_string(),
| ProviderId::Unknown(string) => string.clone(),
}
}
pub fn parse(string: String) -> Self {
match string.as_str() {
| "password" => ProviderId::Password,
| "apple.com" => ProviderId::Apple,
| "gc.apple.com" => ProviderId::AppleGameCenter,
| "facebook.com" => ProviderId::Facebook,
| "github.com" => ProviderId::GitHub,
| "google.com" => ProviderId::Google,
| "playgames.google.com" => ProviderId::GooglePlayGames,
| "linkedin.com" => ProviderId::LinkedIn,
| "microsoft.com" => ProviderId::Microsoft,
| "twitter.com" => ProviderId::Twitter,
| "yahoo.com" => ProviderId::Yahoo,
| _ => ProviderId::Unknown(string),
}
}
}