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