Skip to main content

nominal_api/conjure/objects/scout/datareview/api/
check_alert_action.rs

1use conjure_object::serde::{ser, de};
2use conjure_object::serde::ser::SerializeMap as SerializeMap_;
3use conjure_object::private::{UnionField_, UnionTypeField_};
4use std::fmt;
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub enum CheckAlertAction {
7    CloseWithIgnore(super::CloseWithIgnoreAlert),
8    CloseWithFurtherAction(super::CloseWithFurtherAction),
9    Reopen(super::Reopen),
10    Reassign(super::Reassign),
11    UpdateNotes(super::UpdateNotes),
12    LinkNotebook(super::LinkNotebook),
13    UnlinkNotebook(super::UnlinkNotebook),
14    ArchiveDataReview(super::ArchiveDataReview),
15    UnarchiveDataReview(super::UnarchiveDataReview),
16    /// An unknown variant.
17    Unknown(Unknown),
18}
19impl ser::Serialize for CheckAlertAction {
20    fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
21    where
22        S: ser::Serializer,
23    {
24        let mut map = s.serialize_map(Some(2))?;
25        match self {
26            CheckAlertAction::CloseWithIgnore(value) => {
27                map.serialize_entry(&"type", &"closeWithIgnore")?;
28                map.serialize_entry(&"closeWithIgnore", value)?;
29            }
30            CheckAlertAction::CloseWithFurtherAction(value) => {
31                map.serialize_entry(&"type", &"closeWithFurtherAction")?;
32                map.serialize_entry(&"closeWithFurtherAction", value)?;
33            }
34            CheckAlertAction::Reopen(value) => {
35                map.serialize_entry(&"type", &"reopen")?;
36                map.serialize_entry(&"reopen", value)?;
37            }
38            CheckAlertAction::Reassign(value) => {
39                map.serialize_entry(&"type", &"reassign")?;
40                map.serialize_entry(&"reassign", value)?;
41            }
42            CheckAlertAction::UpdateNotes(value) => {
43                map.serialize_entry(&"type", &"updateNotes")?;
44                map.serialize_entry(&"updateNotes", value)?;
45            }
46            CheckAlertAction::LinkNotebook(value) => {
47                map.serialize_entry(&"type", &"linkNotebook")?;
48                map.serialize_entry(&"linkNotebook", value)?;
49            }
50            CheckAlertAction::UnlinkNotebook(value) => {
51                map.serialize_entry(&"type", &"unlinkNotebook")?;
52                map.serialize_entry(&"unlinkNotebook", value)?;
53            }
54            CheckAlertAction::ArchiveDataReview(value) => {
55                map.serialize_entry(&"type", &"archiveDataReview")?;
56                map.serialize_entry(&"archiveDataReview", value)?;
57            }
58            CheckAlertAction::UnarchiveDataReview(value) => {
59                map.serialize_entry(&"type", &"unarchiveDataReview")?;
60                map.serialize_entry(&"unarchiveDataReview", value)?;
61            }
62            CheckAlertAction::Unknown(value) => {
63                map.serialize_entry(&"type", &value.type_)?;
64                map.serialize_entry(&value.type_, &value.value)?;
65            }
66        }
67        map.end()
68    }
69}
70impl<'de> de::Deserialize<'de> for CheckAlertAction {
71    fn deserialize<D>(d: D) -> Result<CheckAlertAction, D::Error>
72    where
73        D: de::Deserializer<'de>,
74    {
75        d.deserialize_map(Visitor_)
76    }
77}
78struct Visitor_;
79impl<'de> de::Visitor<'de> for Visitor_ {
80    type Value = CheckAlertAction;
81    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
82        fmt.write_str("union CheckAlertAction")
83    }
84    fn visit_map<A>(self, mut map: A) -> Result<CheckAlertAction, A::Error>
85    where
86        A: de::MapAccess<'de>,
87    {
88        let v = match map.next_key::<UnionField_<Variant_>>()? {
89            Some(UnionField_::Type) => {
90                let variant = map.next_value()?;
91                let key = map.next_key()?;
92                match (variant, key) {
93                    (Variant_::CloseWithIgnore, Some(Variant_::CloseWithIgnore)) => {
94                        let value = map.next_value()?;
95                        CheckAlertAction::CloseWithIgnore(value)
96                    }
97                    (
98                        Variant_::CloseWithFurtherAction,
99                        Some(Variant_::CloseWithFurtherAction),
100                    ) => {
101                        let value = map.next_value()?;
102                        CheckAlertAction::CloseWithFurtherAction(value)
103                    }
104                    (Variant_::Reopen, Some(Variant_::Reopen)) => {
105                        let value = map.next_value()?;
106                        CheckAlertAction::Reopen(value)
107                    }
108                    (Variant_::Reassign, Some(Variant_::Reassign)) => {
109                        let value = map.next_value()?;
110                        CheckAlertAction::Reassign(value)
111                    }
112                    (Variant_::UpdateNotes, Some(Variant_::UpdateNotes)) => {
113                        let value = map.next_value()?;
114                        CheckAlertAction::UpdateNotes(value)
115                    }
116                    (Variant_::LinkNotebook, Some(Variant_::LinkNotebook)) => {
117                        let value = map.next_value()?;
118                        CheckAlertAction::LinkNotebook(value)
119                    }
120                    (Variant_::UnlinkNotebook, Some(Variant_::UnlinkNotebook)) => {
121                        let value = map.next_value()?;
122                        CheckAlertAction::UnlinkNotebook(value)
123                    }
124                    (Variant_::ArchiveDataReview, Some(Variant_::ArchiveDataReview)) => {
125                        let value = map.next_value()?;
126                        CheckAlertAction::ArchiveDataReview(value)
127                    }
128                    (
129                        Variant_::UnarchiveDataReview,
130                        Some(Variant_::UnarchiveDataReview),
131                    ) => {
132                        let value = map.next_value()?;
133                        CheckAlertAction::UnarchiveDataReview(value)
134                    }
135                    (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
136                        if type_ == b {
137                            let value = map.next_value()?;
138                            CheckAlertAction::Unknown(Unknown { type_, value })
139                        } else {
140                            return Err(
141                                de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
142                            )
143                        }
144                    }
145                    (variant, Some(key)) => {
146                        return Err(
147                            de::Error::invalid_value(
148                                de::Unexpected::Str(key.as_str()),
149                                &variant.as_str(),
150                            ),
151                        );
152                    }
153                    (variant, None) => {
154                        return Err(de::Error::missing_field(variant.as_str()));
155                    }
156                }
157            }
158            Some(UnionField_::Value(variant)) => {
159                let value = match &variant {
160                    Variant_::CloseWithIgnore => {
161                        let value = map.next_value()?;
162                        CheckAlertAction::CloseWithIgnore(value)
163                    }
164                    Variant_::CloseWithFurtherAction => {
165                        let value = map.next_value()?;
166                        CheckAlertAction::CloseWithFurtherAction(value)
167                    }
168                    Variant_::Reopen => {
169                        let value = map.next_value()?;
170                        CheckAlertAction::Reopen(value)
171                    }
172                    Variant_::Reassign => {
173                        let value = map.next_value()?;
174                        CheckAlertAction::Reassign(value)
175                    }
176                    Variant_::UpdateNotes => {
177                        let value = map.next_value()?;
178                        CheckAlertAction::UpdateNotes(value)
179                    }
180                    Variant_::LinkNotebook => {
181                        let value = map.next_value()?;
182                        CheckAlertAction::LinkNotebook(value)
183                    }
184                    Variant_::UnlinkNotebook => {
185                        let value = map.next_value()?;
186                        CheckAlertAction::UnlinkNotebook(value)
187                    }
188                    Variant_::ArchiveDataReview => {
189                        let value = map.next_value()?;
190                        CheckAlertAction::ArchiveDataReview(value)
191                    }
192                    Variant_::UnarchiveDataReview => {
193                        let value = map.next_value()?;
194                        CheckAlertAction::UnarchiveDataReview(value)
195                    }
196                    Variant_::Unknown(type_) => {
197                        let value = map.next_value()?;
198                        CheckAlertAction::Unknown(Unknown {
199                            type_: type_.clone(),
200                            value,
201                        })
202                    }
203                };
204                if map.next_key::<UnionTypeField_>()?.is_none() {
205                    return Err(de::Error::missing_field("type"));
206                }
207                let type_variant = map.next_value::<Variant_>()?;
208                if variant != type_variant {
209                    return Err(
210                        de::Error::invalid_value(
211                            de::Unexpected::Str(type_variant.as_str()),
212                            &variant.as_str(),
213                        ),
214                    );
215                }
216                value
217            }
218            None => return Err(de::Error::missing_field("type")),
219        };
220        if map.next_key::<UnionField_<Variant_>>()?.is_some() {
221            return Err(de::Error::invalid_length(3, &"type and value fields"));
222        }
223        Ok(v)
224    }
225}
226#[derive(PartialEq)]
227enum Variant_ {
228    CloseWithIgnore,
229    CloseWithFurtherAction,
230    Reopen,
231    Reassign,
232    UpdateNotes,
233    LinkNotebook,
234    UnlinkNotebook,
235    ArchiveDataReview,
236    UnarchiveDataReview,
237    Unknown(Box<str>),
238}
239impl Variant_ {
240    fn as_str(&self) -> &'static str {
241        match *self {
242            Variant_::CloseWithIgnore => "closeWithIgnore",
243            Variant_::CloseWithFurtherAction => "closeWithFurtherAction",
244            Variant_::Reopen => "reopen",
245            Variant_::Reassign => "reassign",
246            Variant_::UpdateNotes => "updateNotes",
247            Variant_::LinkNotebook => "linkNotebook",
248            Variant_::UnlinkNotebook => "unlinkNotebook",
249            Variant_::ArchiveDataReview => "archiveDataReview",
250            Variant_::UnarchiveDataReview => "unarchiveDataReview",
251            Variant_::Unknown(_) => "unknown variant",
252        }
253    }
254}
255impl<'de> de::Deserialize<'de> for Variant_ {
256    fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
257    where
258        D: de::Deserializer<'de>,
259    {
260        d.deserialize_str(VariantVisitor_)
261    }
262}
263struct VariantVisitor_;
264impl<'de> de::Visitor<'de> for VariantVisitor_ {
265    type Value = Variant_;
266    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
267        fmt.write_str("string")
268    }
269    fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
270    where
271        E: de::Error,
272    {
273        let v = match value {
274            "closeWithIgnore" => Variant_::CloseWithIgnore,
275            "closeWithFurtherAction" => Variant_::CloseWithFurtherAction,
276            "reopen" => Variant_::Reopen,
277            "reassign" => Variant_::Reassign,
278            "updateNotes" => Variant_::UpdateNotes,
279            "linkNotebook" => Variant_::LinkNotebook,
280            "unlinkNotebook" => Variant_::UnlinkNotebook,
281            "archiveDataReview" => Variant_::ArchiveDataReview,
282            "unarchiveDataReview" => Variant_::UnarchiveDataReview,
283            value => Variant_::Unknown(value.to_string().into_boxed_str()),
284        };
285        Ok(v)
286    }
287}
288///An unknown variant of the CheckAlertAction union.
289#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
290pub struct Unknown {
291    type_: Box<str>,
292    value: conjure_object::Any,
293}
294impl Unknown {
295    /// Returns the unknown variant's type name.
296    #[inline]
297    pub fn type_(&self) -> &str {
298        &self.type_
299    }
300}