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