Skip to main content

backbone_integrations/domain/entity/
connector_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 = "connector_status", rename_all = "snake_case")]
11pub enum ConnectorStatus {
12    Active,
13    Inactive,
14}
15
16impl std::fmt::Display for ConnectorStatus {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        match self {
19            Self::Active => write!(f, "active"),
20            Self::Inactive => write!(f, "inactive"),
21        }
22    }
23}
24
25impl FromStr for ConnectorStatus {
26    type Err = String;
27
28    fn from_str(s: &str) -> Result<Self, Self::Err> {
29        match s.to_lowercase().as_str() {
30            "active" => Ok(Self::Active),
31            "inactive" => Ok(Self::Inactive),
32            _ => Err(format!("Unknown ConnectorStatus variant: {}", s)),
33        }
34    }
35}
36
37impl Default for ConnectorStatus {
38    fn default() -> Self {
39        Self::Active
40    }
41}