Skip to main content

backbone_inventory/domain/entity/
location_usage.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 = "location_usage", rename_all = "snake_case")]
11pub enum LocationUsage {
12    Supplier,
13    View,
14    Internal,
15    Customer,
16    Inventory,
17    Production,
18    Transit,
19}
20
21impl std::fmt::Display for LocationUsage {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        match self {
24            Self::Supplier => write!(f, "supplier"),
25            Self::View => write!(f, "view"),
26            Self::Internal => write!(f, "internal"),
27            Self::Customer => write!(f, "customer"),
28            Self::Inventory => write!(f, "inventory"),
29            Self::Production => write!(f, "production"),
30            Self::Transit => write!(f, "transit"),
31        }
32    }
33}
34
35impl FromStr for LocationUsage {
36    type Err = String;
37
38    fn from_str(s: &str) -> Result<Self, Self::Err> {
39        match s.to_lowercase().as_str() {
40            "supplier" => Ok(Self::Supplier),
41            "view" => Ok(Self::View),
42            "internal" => Ok(Self::Internal),
43            "customer" => Ok(Self::Customer),
44            "inventory" => Ok(Self::Inventory),
45            "production" => Ok(Self::Production),
46            "transit" => Ok(Self::Transit),
47            _ => Err(format!("Unknown LocationUsage variant: {}", s)),
48        }
49    }
50}
51
52impl Default for LocationUsage {
53    fn default() -> Self {
54        Self::Internal
55    }
56}