domain/reservation/
mod.rs1mod error;
2
3use serde::{Deserialize, Deserializer, Serialize};
4
5pub use error::{Error, Result};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
8pub struct MinimumAgeWeeks(u8);
10
11impl MinimumAgeWeeks {
12 pub fn try_new(value: u8) -> Result<Self> {
14 if value == 0 {
15 return Err(Error::EmptyMinimumAge);
16 }
17 Ok(Self(value))
18 }
19
20 pub const fn get(self) -> u8 {
22 self.0
23 }
24}
25
26impl<'de> Deserialize<'de> for MinimumAgeWeeks {
27 fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
28 where
29 D: Deserializer<'de>,
30 {
31 Self::try_new(u8::deserialize(deserializer)?).map_err(serde::de::Error::custom)
32 }
33}
34
35#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
36pub enum AgePolicyReason {
38 BoardingMinimum,
40 DayPlayMinimum,
42 DaycareMinimum,
44 ServiceSpecificMinimum,
46}
47
48#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
49pub struct AgeThreshold {
51 minimum: MinimumAgeWeeks,
52 reason: AgePolicyReason,
53}
54
55impl AgeThreshold {
56 pub const fn new(minimum: MinimumAgeWeeks, reason: AgePolicyReason) -> Self {
58 Self { minimum, reason }
59 }
60
61 pub const fn minimum(&self) -> MinimumAgeWeeks {
63 self.minimum
64 }
65
66 pub const fn reason(&self) -> AgePolicyReason {
68 self.reason
69 }
70}
71
72#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
73pub struct AddOnLabel(String);
75
76impl AddOnLabel {
77 pub fn try_new(value: impl Into<String>) -> Result<Self> {
79 let value = value.into().trim().to_string();
80 if value.is_empty() {
81 return Err(Error::EmptyAddOnLabel);
82 }
83 if value.chars().count() > 120 {
84 return Err(Error::AddOnLabelTooLong);
85 }
86 Ok(Self(value))
87 }
88
89 pub fn into_inner(self) -> String {
91 self.0
92 }
93}
94
95impl<'de> Deserialize<'de> for AddOnLabel {
96 fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
97 where
98 D: Deserializer<'de>,
99 {
100 Self::try_new(String::deserialize(deserializer)?).map_err(serde::de::Error::custom)
101 }
102}
103
104#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
105pub enum TransitionReason {
107 CustomerRequested,
109 CapacityUnavailable,
111 PolicyHardStop,
113 MissingRequiredInformation,
115 StaffOverride,
117}