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