datadog_api_client/datadogV2/model/
model_case_attributes.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 CaseAttributes {
14    #[serde(
16        rename = "archived_at",
17        default,
18        with = "::serde_with::rust::double_option"
19    )]
20    pub archived_at: Option<Option<chrono::DateTime<chrono::Utc>>>,
21    #[serde(rename = "attributes")]
23    pub attributes: Option<std::collections::BTreeMap<String, Vec<String>>>,
24    #[serde(
26        rename = "closed_at",
27        default,
28        with = "::serde_with::rust::double_option"
29    )]
30    pub closed_at: Option<Option<chrono::DateTime<chrono::Utc>>>,
31    #[serde(rename = "created_at")]
33    pub created_at: Option<chrono::DateTime<chrono::Utc>>,
34    #[serde(rename = "custom_attributes")]
36    pub custom_attributes:
37        Option<std::collections::BTreeMap<String, crate::datadogV2::model::CustomAttributeValue>>,
38    #[serde(rename = "description")]
40    pub description: Option<String>,
41    #[serde(
43        rename = "jira_issue",
44        default,
45        with = "::serde_with::rust::double_option"
46    )]
47    pub jira_issue: Option<Option<crate::datadogV2::model::JiraIssue>>,
48    #[serde(rename = "key")]
50    pub key: Option<String>,
51    #[serde(
53        rename = "modified_at",
54        default,
55        with = "::serde_with::rust::double_option"
56    )]
57    pub modified_at: Option<Option<chrono::DateTime<chrono::Utc>>>,
58    #[serde(rename = "priority")]
60    pub priority: Option<crate::datadogV2::model::CasePriority>,
61    #[serde(
63        rename = "service_now_ticket",
64        default,
65        with = "::serde_with::rust::double_option"
66    )]
67    pub service_now_ticket: Option<Option<crate::datadogV2::model::ServiceNowTicket>>,
68    #[serde(rename = "status")]
70    pub status: Option<crate::datadogV2::model::CaseStatus>,
71    #[serde(rename = "title")]
73    pub title: Option<String>,
74    #[deprecated]
76    #[serde(rename = "type")]
77    pub type_: Option<crate::datadogV2::model::CaseType>,
78    #[serde(rename = "type_id")]
80    pub type_id: Option<String>,
81    #[serde(flatten)]
82    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
83    #[serde(skip)]
84    #[serde(default)]
85    pub(crate) _unparsed: bool,
86}
87
88impl CaseAttributes {
89    pub fn new() -> CaseAttributes {
90        #[allow(deprecated)]
91        CaseAttributes {
92            archived_at: None,
93            attributes: None,
94            closed_at: None,
95            created_at: None,
96            custom_attributes: None,
97            description: None,
98            jira_issue: None,
99            key: None,
100            modified_at: None,
101            priority: None,
102            service_now_ticket: None,
103            status: None,
104            title: None,
105            type_: None,
106            type_id: None,
107            additional_properties: std::collections::BTreeMap::new(),
108            _unparsed: false,
109        }
110    }
111
112    #[allow(deprecated)]
113    pub fn archived_at(mut self, value: Option<chrono::DateTime<chrono::Utc>>) -> Self {
114        self.archived_at = Some(value);
115        self
116    }
117
118    #[allow(deprecated)]
119    pub fn attributes(mut self, value: std::collections::BTreeMap<String, Vec<String>>) -> Self {
120        self.attributes = Some(value);
121        self
122    }
123
124    #[allow(deprecated)]
125    pub fn closed_at(mut self, value: Option<chrono::DateTime<chrono::Utc>>) -> Self {
126        self.closed_at = Some(value);
127        self
128    }
129
130    #[allow(deprecated)]
131    pub fn created_at(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
132        self.created_at = Some(value);
133        self
134    }
135
136    #[allow(deprecated)]
137    pub fn custom_attributes(
138        mut self,
139        value: std::collections::BTreeMap<String, crate::datadogV2::model::CustomAttributeValue>,
140    ) -> Self {
141        self.custom_attributes = Some(value);
142        self
143    }
144
145    #[allow(deprecated)]
146    pub fn description(mut self, value: String) -> Self {
147        self.description = Some(value);
148        self
149    }
150
151    #[allow(deprecated)]
152    pub fn jira_issue(mut self, value: Option<crate::datadogV2::model::JiraIssue>) -> Self {
153        self.jira_issue = Some(value);
154        self
155    }
156
157    #[allow(deprecated)]
158    pub fn key(mut self, value: String) -> Self {
159        self.key = Some(value);
160        self
161    }
162
163    #[allow(deprecated)]
164    pub fn modified_at(mut self, value: Option<chrono::DateTime<chrono::Utc>>) -> Self {
165        self.modified_at = Some(value);
166        self
167    }
168
169    #[allow(deprecated)]
170    pub fn priority(mut self, value: crate::datadogV2::model::CasePriority) -> Self {
171        self.priority = Some(value);
172        self
173    }
174
175    #[allow(deprecated)]
176    pub fn service_now_ticket(
177        mut self,
178        value: Option<crate::datadogV2::model::ServiceNowTicket>,
179    ) -> Self {
180        self.service_now_ticket = Some(value);
181        self
182    }
183
184    #[allow(deprecated)]
185    pub fn status(mut self, value: crate::datadogV2::model::CaseStatus) -> Self {
186        self.status = Some(value);
187        self
188    }
189
190    #[allow(deprecated)]
191    pub fn title(mut self, value: String) -> Self {
192        self.title = Some(value);
193        self
194    }
195
196    #[allow(deprecated)]
197    pub fn type_(mut self, value: crate::datadogV2::model::CaseType) -> Self {
198        self.type_ = Some(value);
199        self
200    }
201
202    #[allow(deprecated)]
203    pub fn type_id(mut self, value: String) -> Self {
204        self.type_id = Some(value);
205        self
206    }
207
208    pub fn additional_properties(
209        mut self,
210        value: std::collections::BTreeMap<String, serde_json::Value>,
211    ) -> Self {
212        self.additional_properties = value;
213        self
214    }
215}
216
217impl Default for CaseAttributes {
218    fn default() -> Self {
219        Self::new()
220    }
221}
222
223impl<'de> Deserialize<'de> for CaseAttributes {
224    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
225    where
226        D: Deserializer<'de>,
227    {
228        struct CaseAttributesVisitor;
229        impl<'a> Visitor<'a> for CaseAttributesVisitor {
230            type Value = CaseAttributes;
231
232            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
233                f.write_str("a mapping")
234            }
235
236            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
237            where
238                M: MapAccess<'a>,
239            {
240                let mut archived_at: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
241                let mut attributes: Option<std::collections::BTreeMap<String, Vec<String>>> = None;
242                let mut closed_at: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
243                let mut created_at: Option<chrono::DateTime<chrono::Utc>> = None;
244                let mut custom_attributes: Option<
245                    std::collections::BTreeMap<
246                        String,
247                        crate::datadogV2::model::CustomAttributeValue,
248                    >,
249                > = None;
250                let mut description: Option<String> = None;
251                let mut jira_issue: Option<Option<crate::datadogV2::model::JiraIssue>> = None;
252                let mut key: Option<String> = None;
253                let mut modified_at: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
254                let mut priority: Option<crate::datadogV2::model::CasePriority> = None;
255                let mut service_now_ticket: Option<
256                    Option<crate::datadogV2::model::ServiceNowTicket>,
257                > = None;
258                let mut status: Option<crate::datadogV2::model::CaseStatus> = None;
259                let mut title: Option<String> = None;
260                let mut type_: Option<crate::datadogV2::model::CaseType> = None;
261                let mut type_id: Option<String> = None;
262                let mut additional_properties: std::collections::BTreeMap<
263                    String,
264                    serde_json::Value,
265                > = std::collections::BTreeMap::new();
266                let mut _unparsed = false;
267
268                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
269                    match k.as_str() {
270                        "archived_at" => {
271                            archived_at =
272                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
273                        }
274                        "attributes" => {
275                            if v.is_null() {
276                                continue;
277                            }
278                            attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
279                        }
280                        "closed_at" => {
281                            closed_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
282                        }
283                        "created_at" => {
284                            if v.is_null() {
285                                continue;
286                            }
287                            created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
288                        }
289                        "custom_attributes" => {
290                            if v.is_null() {
291                                continue;
292                            }
293                            custom_attributes =
294                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
295                        }
296                        "description" => {
297                            if v.is_null() {
298                                continue;
299                            }
300                            description =
301                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
302                        }
303                        "jira_issue" => {
304                            jira_issue = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
305                        }
306                        "key" => {
307                            if v.is_null() {
308                                continue;
309                            }
310                            key = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
311                        }
312                        "modified_at" => {
313                            modified_at =
314                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
315                        }
316                        "priority" => {
317                            if v.is_null() {
318                                continue;
319                            }
320                            priority = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
321                            if let Some(ref _priority) = priority {
322                                match _priority {
323                                    crate::datadogV2::model::CasePriority::UnparsedObject(
324                                        _priority,
325                                    ) => {
326                                        _unparsed = true;
327                                    }
328                                    _ => {}
329                                }
330                            }
331                        }
332                        "service_now_ticket" => {
333                            service_now_ticket =
334                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
335                        }
336                        "status" => {
337                            if v.is_null() {
338                                continue;
339                            }
340                            status = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
341                            if let Some(ref _status) = status {
342                                match _status {
343                                    crate::datadogV2::model::CaseStatus::UnparsedObject(
344                                        _status,
345                                    ) => {
346                                        _unparsed = true;
347                                    }
348                                    _ => {}
349                                }
350                            }
351                        }
352                        "title" => {
353                            if v.is_null() {
354                                continue;
355                            }
356                            title = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
357                        }
358                        "type" => {
359                            if v.is_null() {
360                                continue;
361                            }
362                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
363                            if let Some(ref _type_) = type_ {
364                                match _type_ {
365                                    crate::datadogV2::model::CaseType::UnparsedObject(_type_) => {
366                                        _unparsed = true;
367                                    }
368                                    _ => {}
369                                }
370                            }
371                        }
372                        "type_id" => {
373                            if v.is_null() {
374                                continue;
375                            }
376                            type_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
377                        }
378                        &_ => {
379                            if let Ok(value) = serde_json::from_value(v.clone()) {
380                                additional_properties.insert(k, value);
381                            }
382                        }
383                    }
384                }
385
386                #[allow(deprecated)]
387                let content = CaseAttributes {
388                    archived_at,
389                    attributes,
390                    closed_at,
391                    created_at,
392                    custom_attributes,
393                    description,
394                    jira_issue,
395                    key,
396                    modified_at,
397                    priority,
398                    service_now_ticket,
399                    status,
400                    title,
401                    type_,
402                    type_id,
403                    additional_properties,
404                    _unparsed,
405                };
406
407                Ok(content)
408            }
409        }
410
411        deserializer.deserialize_any(CaseAttributesVisitor)
412    }
413}