datadog_api_client/datadogV2/model/
model_incident_create_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 IncidentCreateAttributes {
14 #[serde(rename = "customer_impact_scope")]
16 pub customer_impact_scope: Option<String>,
17 #[serde(rename = "customer_impacted")]
19 pub customer_impacted: bool,
20 #[serde(rename = "fields")]
22 pub fields: Option<
23 std::collections::BTreeMap<String, crate::datadogV2::model::IncidentFieldAttributes>,
24 >,
25 #[serde(rename = "incident_type_uuid")]
27 pub incident_type_uuid: Option<String>,
28 #[serde(rename = "initial_cells")]
30 pub initial_cells: Option<Vec<crate::datadogV2::model::IncidentTimelineCellCreateAttributes>>,
31 #[serde(rename = "is_test")]
33 pub is_test: Option<bool>,
34 #[serde(rename = "notification_handles")]
36 pub notification_handles: Option<Vec<crate::datadogV2::model::IncidentNotificationHandle>>,
37 #[serde(rename = "title")]
39 pub title: String,
40 #[serde(flatten)]
41 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
42 #[serde(skip)]
43 #[serde(default)]
44 pub(crate) _unparsed: bool,
45}
46
47impl IncidentCreateAttributes {
48 pub fn new(customer_impacted: bool, title: String) -> IncidentCreateAttributes {
49 IncidentCreateAttributes {
50 customer_impact_scope: None,
51 customer_impacted,
52 fields: None,
53 incident_type_uuid: None,
54 initial_cells: None,
55 is_test: None,
56 notification_handles: None,
57 title,
58 additional_properties: std::collections::BTreeMap::new(),
59 _unparsed: false,
60 }
61 }
62
63 pub fn customer_impact_scope(mut self, value: String) -> Self {
64 self.customer_impact_scope = Some(value);
65 self
66 }
67
68 pub fn fields(
69 mut self,
70 value: std::collections::BTreeMap<String, crate::datadogV2::model::IncidentFieldAttributes>,
71 ) -> Self {
72 self.fields = Some(value);
73 self
74 }
75
76 pub fn incident_type_uuid(mut self, value: String) -> Self {
77 self.incident_type_uuid = Some(value);
78 self
79 }
80
81 pub fn initial_cells(
82 mut self,
83 value: Vec<crate::datadogV2::model::IncidentTimelineCellCreateAttributes>,
84 ) -> Self {
85 self.initial_cells = Some(value);
86 self
87 }
88
89 pub fn is_test(mut self, value: bool) -> Self {
90 self.is_test = Some(value);
91 self
92 }
93
94 pub fn notification_handles(
95 mut self,
96 value: Vec<crate::datadogV2::model::IncidentNotificationHandle>,
97 ) -> Self {
98 self.notification_handles = Some(value);
99 self
100 }
101
102 pub fn additional_properties(
103 mut self,
104 value: std::collections::BTreeMap<String, serde_json::Value>,
105 ) -> Self {
106 self.additional_properties = value;
107 self
108 }
109}
110
111impl<'de> Deserialize<'de> for IncidentCreateAttributes {
112 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
113 where
114 D: Deserializer<'de>,
115 {
116 struct IncidentCreateAttributesVisitor;
117 impl<'a> Visitor<'a> for IncidentCreateAttributesVisitor {
118 type Value = IncidentCreateAttributes;
119
120 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
121 f.write_str("a mapping")
122 }
123
124 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
125 where
126 M: MapAccess<'a>,
127 {
128 let mut customer_impact_scope: Option<String> = None;
129 let mut customer_impacted: Option<bool> = None;
130 let mut fields: Option<
131 std::collections::BTreeMap<
132 String,
133 crate::datadogV2::model::IncidentFieldAttributes,
134 >,
135 > = None;
136 let mut incident_type_uuid: Option<String> = None;
137 let mut initial_cells: Option<
138 Vec<crate::datadogV2::model::IncidentTimelineCellCreateAttributes>,
139 > = None;
140 let mut is_test: Option<bool> = None;
141 let mut notification_handles: Option<
142 Vec<crate::datadogV2::model::IncidentNotificationHandle>,
143 > = None;
144 let mut title: Option<String> = None;
145 let mut additional_properties: std::collections::BTreeMap<
146 String,
147 serde_json::Value,
148 > = std::collections::BTreeMap::new();
149 let mut _unparsed = false;
150
151 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
152 match k.as_str() {
153 "customer_impact_scope" => {
154 if v.is_null() {
155 continue;
156 }
157 customer_impact_scope =
158 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
159 }
160 "customer_impacted" => {
161 customer_impacted =
162 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
163 }
164 "fields" => {
165 if v.is_null() {
166 continue;
167 }
168 fields = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
169 }
170 "incident_type_uuid" => {
171 if v.is_null() {
172 continue;
173 }
174 incident_type_uuid =
175 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
176 }
177 "initial_cells" => {
178 if v.is_null() {
179 continue;
180 }
181 initial_cells =
182 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
183 }
184 "is_test" => {
185 if v.is_null() {
186 continue;
187 }
188 is_test = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
189 }
190 "notification_handles" => {
191 if v.is_null() {
192 continue;
193 }
194 notification_handles =
195 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
196 }
197 "title" => {
198 title = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
199 }
200 &_ => {
201 if let Ok(value) = serde_json::from_value(v.clone()) {
202 additional_properties.insert(k, value);
203 }
204 }
205 }
206 }
207 let customer_impacted = customer_impacted
208 .ok_or_else(|| M::Error::missing_field("customer_impacted"))?;
209 let title = title.ok_or_else(|| M::Error::missing_field("title"))?;
210
211 let content = IncidentCreateAttributes {
212 customer_impact_scope,
213 customer_impacted,
214 fields,
215 incident_type_uuid,
216 initial_cells,
217 is_test,
218 notification_handles,
219 title,
220 additional_properties,
221 _unparsed,
222 };
223
224 Ok(content)
225 }
226 }
227
228 deserializer.deserialize_any(IncidentCreateAttributesVisitor)
229 }
230}