backbone_integrations/domain/entity/
o_auth_provider.rs1use serde::{Deserialize, Serialize};
2use sqlx::Type;
3use std::str::FromStr;
4#[cfg(feature = "openapi")]
5use utoipa::ToSchema;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Type)]
8#[cfg_attr(feature = "openapi", derive(ToSchema))]
9#[serde(rename_all = "snake_case")]
10#[sqlx(type_name = "o_auth_provider", rename_all = "snake_case")]
11pub enum OAuthProvider {
12 Gmail,
13 Outlook,
14 GoogleCalendar,
15 MicrosoftCalendar,
16}
17
18impl std::fmt::Display for OAuthProvider {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 match self {
21 Self::Gmail => write!(f, "gmail"),
22 Self::Outlook => write!(f, "outlook"),
23 Self::GoogleCalendar => write!(f, "google_calendar"),
24 Self::MicrosoftCalendar => write!(f, "microsoft_calendar"),
25 }
26 }
27}
28
29impl FromStr for OAuthProvider {
30 type Err = String;
31
32 fn from_str(s: &str) -> Result<Self, Self::Err> {
33 match s.to_lowercase().as_str() {
34 "gmail" => Ok(Self::Gmail),
35 "outlook" => Ok(Self::Outlook),
36 "google_calendar" => Ok(Self::GoogleCalendar),
37 "microsoft_calendar" => Ok(Self::MicrosoftCalendar),
38 _ => Err(format!("Unknown OAuthProvider variant: {}", s)),
39 }
40 }
41}
42
43impl Default for OAuthProvider {
44 fn default() -> Self {
45 Self::Gmail
46 }
47}