Skip to main content

backbone_integrations/domain/entity/
integration_account_status.rs

1use 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 = "integration_account_status", rename_all = "snake_case")]
11pub enum IntegrationAccountStatus {
12    Pending,
13    Active,
14    Expired,
15    Revoked,
16}
17
18impl std::fmt::Display for IntegrationAccountStatus {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        match self {
21            Self::Pending => write!(f, "pending"),
22            Self::Active => write!(f, "active"),
23            Self::Expired => write!(f, "expired"),
24            Self::Revoked => write!(f, "revoked"),
25        }
26    }
27}
28
29impl FromStr for IntegrationAccountStatus {
30    type Err = String;
31
32    fn from_str(s: &str) -> Result<Self, Self::Err> {
33        match s.to_lowercase().as_str() {
34            "pending" => Ok(Self::Pending),
35            "active" => Ok(Self::Active),
36            "expired" => Ok(Self::Expired),
37            "revoked" => Ok(Self::Revoked),
38            _ => Err(format!("Unknown IntegrationAccountStatus variant: {}", s)),
39        }
40    }
41}
42
43impl Default for IntegrationAccountStatus {
44    fn default() -> Self {
45        Self::Pending
46    }
47}