Skip to main content

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