datadog_api_client/datadogV2/model/
model_case_create_attributes.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// Case creation attributes
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct CaseCreateAttributes {
14    /// Description
15    #[serde(rename = "description")]
16    pub description: Option<String>,
17    /// Case priority
18    #[serde(rename = "priority")]
19    pub priority: Option<crate::datadogV2::model::CasePriority>,
20    /// Title
21    #[serde(rename = "title")]
22    pub title: String,
23    /// Case type
24    #[serde(rename = "type")]
25    pub type_: crate::datadogV2::model::CaseType,
26    #[serde(flatten)]
27    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
28    #[serde(skip)]
29    #[serde(default)]
30    pub(crate) _unparsed: bool,
31}
32
33impl CaseCreateAttributes {
34    pub fn new(title: String, type_: crate::datadogV2::model::CaseType) -> CaseCreateAttributes {
35        CaseCreateAttributes {
36            description: None,
37            priority: None,
38            title,
39            type_,
40            additional_properties: std::collections::BTreeMap::new(),
41            _unparsed: false,
42        }
43    }
44
45    pub fn description(mut self, value: String) -> Self {
46        self.description = Some(value);
47        self
48    }
49
50    pub fn priority(mut self, value: crate::datadogV2::model::CasePriority) -> Self {
51        self.priority = Some(value);
52        self
53    }
54
55    pub fn additional_properties(
56        mut self,
57        value: std::collections::BTreeMap<String, serde_json::Value>,
58    ) -> Self {
59        self.additional_properties = value;
60        self
61    }
62}
63
64impl<'de> Deserialize<'de> for CaseCreateAttributes {
65    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
66    where
67        D: Deserializer<'de>,
68    {
69        struct CaseCreateAttributesVisitor;
70        impl<'a> Visitor<'a> for CaseCreateAttributesVisitor {
71            type Value = CaseCreateAttributes;
72
73            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
74                f.write_str("a mapping")
75            }
76
77            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
78            where
79                M: MapAccess<'a>,
80            {
81                let mut description: Option<String> = None;
82                let mut priority: Option<crate::datadogV2::model::CasePriority> = None;
83                let mut title: Option<String> = None;
84                let mut type_: Option<crate::datadogV2::model::CaseType> = None;
85                let mut additional_properties: std::collections::BTreeMap<
86                    String,
87                    serde_json::Value,
88                > = std::collections::BTreeMap::new();
89                let mut _unparsed = false;
90
91                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
92                    match k.as_str() {
93                        "description" => {
94                            if v.is_null() {
95                                continue;
96                            }
97                            description =
98                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
99                        }
100                        "priority" => {
101                            if v.is_null() {
102                                continue;
103                            }
104                            priority = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
105                            if let Some(ref _priority) = priority {
106                                match _priority {
107                                    crate::datadogV2::model::CasePriority::UnparsedObject(
108                                        _priority,
109                                    ) => {
110                                        _unparsed = true;
111                                    }
112                                    _ => {}
113                                }
114                            }
115                        }
116                        "title" => {
117                            title = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
118                        }
119                        "type" => {
120                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
121                            if let Some(ref _type_) = type_ {
122                                match _type_ {
123                                    crate::datadogV2::model::CaseType::UnparsedObject(_type_) => {
124                                        _unparsed = true;
125                                    }
126                                    _ => {}
127                                }
128                            }
129                        }
130                        &_ => {
131                            if let Ok(value) = serde_json::from_value(v.clone()) {
132                                additional_properties.insert(k, value);
133                            }
134                        }
135                    }
136                }
137                let title = title.ok_or_else(|| M::Error::missing_field("title"))?;
138                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
139
140                let content = CaseCreateAttributes {
141                    description,
142                    priority,
143                    title,
144                    type_,
145                    additional_properties,
146                    _unparsed,
147                };
148
149                Ok(content)
150            }
151        }
152
153        deserializer.deserialize_any(CaseCreateAttributesVisitor)
154    }
155}