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