backbone_integrations/domain/entity/
integration_status.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 = "integration_status", rename_all = "snake_case")]
11pub enum IntegrationStatus {
12 Received,
13 Mapped,
14 Ignored,
15 Failed,
16}
17
18impl std::fmt::Display for IntegrationStatus {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 match self {
21 Self::Received => write!(f, "received"),
22 Self::Mapped => write!(f, "mapped"),
23 Self::Ignored => write!(f, "ignored"),
24 Self::Failed => write!(f, "failed"),
25 }
26 }
27}
28
29impl FromStr for IntegrationStatus {
30 type Err = String;
31
32 fn from_str(s: &str) -> Result<Self, Self::Err> {
33 match s.to_lowercase().as_str() {
34 "received" => Ok(Self::Received),
35 "mapped" => Ok(Self::Mapped),
36 "ignored" => Ok(Self::Ignored),
37 "failed" => Ok(Self::Failed),
38 _ => Err(format!("Unknown IntegrationStatus variant: {}", s)),
39 }
40 }
41}
42
43impl Default for IntegrationStatus {
44 fn default() -> Self {
45 Self::Received
46 }
47}