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