Skip to main content

backbone_inventory/domain/entity/
move_state.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 = "move_state", rename_all = "snake_case")]
11pub enum MoveState {
12    Draft,
13    Waiting,
14    Confirmed,
15    PartiallyAvailable,
16    Assigned,
17    Done,
18    Cancel,
19}
20
21impl std::fmt::Display for MoveState {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        match self {
24            Self::Draft => write!(f, "draft"),
25            Self::Waiting => write!(f, "waiting"),
26            Self::Confirmed => write!(f, "confirmed"),
27            Self::PartiallyAvailable => write!(f, "partially_available"),
28            Self::Assigned => write!(f, "assigned"),
29            Self::Done => write!(f, "done"),
30            Self::Cancel => write!(f, "cancel"),
31        }
32    }
33}
34
35impl FromStr for MoveState {
36    type Err = String;
37
38    fn from_str(s: &str) -> Result<Self, Self::Err> {
39        match s.to_lowercase().as_str() {
40            "draft" => Ok(Self::Draft),
41            "waiting" => Ok(Self::Waiting),
42            "confirmed" => Ok(Self::Confirmed),
43            "partially_available" => Ok(Self::PartiallyAvailable),
44            "assigned" => Ok(Self::Assigned),
45            "done" => Ok(Self::Done),
46            "cancel" => Ok(Self::Cancel),
47            _ => Err(format!("Unknown MoveState variant: {}", s)),
48        }
49    }
50}
51
52impl Default for MoveState {
53    fn default() -> Self {
54        Self::Draft
55    }
56}