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