Skip to main content

bo4e_core/enums/
contract_form.rs

1//! Contract form (Vertragsform) enumeration.
2
3use serde::{Deserialize, Serialize};
4
5/// Form of contract in tenders and offers.
6///
7/// German: Vertragsform
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
10#[cfg_attr(feature = "json-schema", schemars(rename = "Vertragsform"))]
11#[non_exhaustive]
12pub enum ContractForm {
13    /// Online contract
14    #[serde(rename = "ONLINE")]
15    Online,
16
17    /// Direct contract
18    #[serde(rename = "DIREKT")]
19    Direct,
20
21    /// Fax contract
22    #[serde(rename = "FAX")]
23    Fax,
24}
25
26impl ContractForm {
27    /// Returns the German name.
28    pub fn german_name(&self) -> &'static str {
29        match self {
30            Self::Online => "Online",
31            Self::Direct => "Direkt",
32            Self::Fax => "Auftragsfax",
33        }
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40
41    #[test]
42    fn test_serialize() {
43        assert_eq!(
44            serde_json::to_string(&ContractForm::Online).unwrap(),
45            r#""ONLINE""#
46        );
47        assert_eq!(
48            serde_json::to_string(&ContractForm::Direct).unwrap(),
49            r#""DIREKT""#
50        );
51    }
52
53    #[test]
54    fn test_deserialize() {
55        assert_eq!(
56            serde_json::from_str::<ContractForm>(r#""ONLINE""#).unwrap(),
57            ContractForm::Online
58        );
59        assert_eq!(
60            serde_json::from_str::<ContractForm>(r#""FAX""#).unwrap(),
61            ContractForm::Fax
62        );
63    }
64
65    #[test]
66    fn test_roundtrip() {
67        for form in [
68            ContractForm::Online,
69            ContractForm::Direct,
70            ContractForm::Fax,
71        ] {
72            let json = serde_json::to_string(&form).unwrap();
73            let parsed: ContractForm = serde_json::from_str(&json).unwrap();
74            assert_eq!(form, parsed);
75        }
76    }
77}