datadog_api_client/datadogV2/model/
model_incident_notification_template_array.rs1use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct IncidentNotificationTemplateArray {
14    #[serde(rename = "data")]
16    pub data: Vec<crate::datadogV2::model::IncidentNotificationTemplateResponseData>,
17    #[serde(rename = "included")]
19    pub included: Option<Vec<crate::datadogV2::model::IncidentNotificationTemplateIncludedItems>>,
20    #[serde(rename = "meta")]
22    pub meta: Option<crate::datadogV2::model::IncidentNotificationTemplateArrayMeta>,
23    #[serde(flatten)]
24    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
25    #[serde(skip)]
26    #[serde(default)]
27    pub(crate) _unparsed: bool,
28}
29
30impl IncidentNotificationTemplateArray {
31    pub fn new(
32        data: Vec<crate::datadogV2::model::IncidentNotificationTemplateResponseData>,
33    ) -> IncidentNotificationTemplateArray {
34        IncidentNotificationTemplateArray {
35            data,
36            included: None,
37            meta: None,
38            additional_properties: std::collections::BTreeMap::new(),
39            _unparsed: false,
40        }
41    }
42
43    pub fn included(
44        mut self,
45        value: Vec<crate::datadogV2::model::IncidentNotificationTemplateIncludedItems>,
46    ) -> Self {
47        self.included = Some(value);
48        self
49    }
50
51    pub fn meta(
52        mut self,
53        value: crate::datadogV2::model::IncidentNotificationTemplateArrayMeta,
54    ) -> Self {
55        self.meta = Some(value);
56        self
57    }
58
59    pub fn additional_properties(
60        mut self,
61        value: std::collections::BTreeMap<String, serde_json::Value>,
62    ) -> Self {
63        self.additional_properties = value;
64        self
65    }
66}
67
68impl<'de> Deserialize<'de> for IncidentNotificationTemplateArray {
69    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
70    where
71        D: Deserializer<'de>,
72    {
73        struct IncidentNotificationTemplateArrayVisitor;
74        impl<'a> Visitor<'a> for IncidentNotificationTemplateArrayVisitor {
75            type Value = IncidentNotificationTemplateArray;
76
77            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
78                f.write_str("a mapping")
79            }
80
81            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
82            where
83                M: MapAccess<'a>,
84            {
85                let mut data: Option<
86                    Vec<crate::datadogV2::model::IncidentNotificationTemplateResponseData>,
87                > = None;
88                let mut included: Option<
89                    Vec<crate::datadogV2::model::IncidentNotificationTemplateIncludedItems>,
90                > = None;
91                let mut meta: Option<
92                    crate::datadogV2::model::IncidentNotificationTemplateArrayMeta,
93                > = None;
94                let mut additional_properties: std::collections::BTreeMap<
95                    String,
96                    serde_json::Value,
97                > = std::collections::BTreeMap::new();
98                let mut _unparsed = false;
99
100                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
101                    match k.as_str() {
102                        "data" => {
103                            data = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
104                        }
105                        "included" => {
106                            if v.is_null() {
107                                continue;
108                            }
109                            included = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
110                        }
111                        "meta" => {
112                            if v.is_null() {
113                                continue;
114                            }
115                            meta = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
116                        }
117                        &_ => {
118                            if let Ok(value) = serde_json::from_value(v.clone()) {
119                                additional_properties.insert(k, value);
120                            }
121                        }
122                    }
123                }
124                let data = data.ok_or_else(|| M::Error::missing_field("data"))?;
125
126                let content = IncidentNotificationTemplateArray {
127                    data,
128                    included,
129                    meta,
130                    additional_properties,
131                    _unparsed,
132                };
133
134                Ok(content)
135            }
136        }
137
138        deserializer.deserialize_any(IncidentNotificationTemplateArrayVisitor)
139    }
140}