datadog_api_client/datadogV1/model/
model_service_level_objective.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]
12#[skip_serializing_none]
13#[derive(Clone, Debug, PartialEq, Serialize)]
14pub struct ServiceLevelObjective {
15 #[serde(rename = "created_at")]
19 pub created_at: Option<i64>,
20 #[serde(rename = "creator")]
22 pub creator: Option<crate::datadogV1::model::Creator>,
23 #[serde(
28 rename = "description",
29 default,
30 with = "::serde_with::rust::double_option"
31 )]
32 pub description: Option<Option<String>>,
33 #[serde(rename = "groups")]
39 pub groups: Option<Vec<String>>,
40 #[serde(rename = "id")]
44 pub id: Option<String>,
45 #[serde(rename = "modified_at")]
49 pub modified_at: Option<i64>,
50 #[serde(rename = "monitor_ids")]
53 pub monitor_ids: Option<Vec<i64>>,
54 #[serde(rename = "monitor_tags")]
61 pub monitor_tags: Option<Vec<String>>,
62 #[serde(rename = "name")]
64 pub name: String,
65 #[serde(rename = "query")]
69 pub query: Option<crate::datadogV1::model::ServiceLevelObjectiveQuery>,
70 #[serde(rename = "sli_specification")]
72 pub sli_specification: Option<crate::datadogV1::model::SLOSliSpec>,
73 #[serde(rename = "tags")]
77 pub tags: Option<Vec<String>>,
78 #[serde(rename = "target_threshold")]
81 pub target_threshold: Option<f64>,
82 #[serde(rename = "thresholds")]
85 pub thresholds: Vec<crate::datadogV1::model::SLOThreshold>,
86 #[serde(rename = "timeframe")]
89 pub timeframe: Option<crate::datadogV1::model::SLOTimeframe>,
90 #[serde(rename = "type")]
92 pub type_: crate::datadogV1::model::SLOType,
93 #[serde(rename = "warning_threshold")]
98 pub warning_threshold: Option<f64>,
99 #[serde(flatten)]
100 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
101 #[serde(skip)]
102 #[serde(default)]
103 pub(crate) _unparsed: bool,
104}
105
106impl ServiceLevelObjective {
107 pub fn new(
108 name: String,
109 thresholds: Vec<crate::datadogV1::model::SLOThreshold>,
110 type_: crate::datadogV1::model::SLOType,
111 ) -> ServiceLevelObjective {
112 ServiceLevelObjective {
113 created_at: None,
114 creator: None,
115 description: None,
116 groups: None,
117 id: None,
118 modified_at: None,
119 monitor_ids: None,
120 monitor_tags: None,
121 name,
122 query: None,
123 sli_specification: None,
124 tags: None,
125 target_threshold: None,
126 thresholds,
127 timeframe: None,
128 type_,
129 warning_threshold: None,
130 additional_properties: std::collections::BTreeMap::new(),
131 _unparsed: false,
132 }
133 }
134
135 pub fn created_at(mut self, value: i64) -> Self {
136 self.created_at = Some(value);
137 self
138 }
139
140 pub fn creator(mut self, value: crate::datadogV1::model::Creator) -> Self {
141 self.creator = Some(value);
142 self
143 }
144
145 pub fn description(mut self, value: Option<String>) -> Self {
146 self.description = Some(value);
147 self
148 }
149
150 pub fn groups(mut self, value: Vec<String>) -> Self {
151 self.groups = Some(value);
152 self
153 }
154
155 pub fn id(mut self, value: String) -> Self {
156 self.id = Some(value);
157 self
158 }
159
160 pub fn modified_at(mut self, value: i64) -> Self {
161 self.modified_at = Some(value);
162 self
163 }
164
165 pub fn monitor_ids(mut self, value: Vec<i64>) -> Self {
166 self.monitor_ids = Some(value);
167 self
168 }
169
170 pub fn monitor_tags(mut self, value: Vec<String>) -> Self {
171 self.monitor_tags = Some(value);
172 self
173 }
174
175 pub fn query(mut self, value: crate::datadogV1::model::ServiceLevelObjectiveQuery) -> Self {
176 self.query = Some(value);
177 self
178 }
179
180 pub fn sli_specification(mut self, value: crate::datadogV1::model::SLOSliSpec) -> Self {
181 self.sli_specification = Some(value);
182 self
183 }
184
185 pub fn tags(mut self, value: Vec<String>) -> Self {
186 self.tags = Some(value);
187 self
188 }
189
190 pub fn target_threshold(mut self, value: f64) -> Self {
191 self.target_threshold = Some(value);
192 self
193 }
194
195 pub fn timeframe(mut self, value: crate::datadogV1::model::SLOTimeframe) -> Self {
196 self.timeframe = Some(value);
197 self
198 }
199
200 pub fn warning_threshold(mut self, value: f64) -> Self {
201 self.warning_threshold = Some(value);
202 self
203 }
204
205 pub fn additional_properties(
206 mut self,
207 value: std::collections::BTreeMap<String, serde_json::Value>,
208 ) -> Self {
209 self.additional_properties = value;
210 self
211 }
212}
213
214impl<'de> Deserialize<'de> for ServiceLevelObjective {
215 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
216 where
217 D: Deserializer<'de>,
218 {
219 struct ServiceLevelObjectiveVisitor;
220 impl<'a> Visitor<'a> for ServiceLevelObjectiveVisitor {
221 type Value = ServiceLevelObjective;
222
223 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
224 f.write_str("a mapping")
225 }
226
227 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
228 where
229 M: MapAccess<'a>,
230 {
231 let mut created_at: Option<i64> = None;
232 let mut creator: Option<crate::datadogV1::model::Creator> = None;
233 let mut description: Option<Option<String>> = None;
234 let mut groups: Option<Vec<String>> = None;
235 let mut id: Option<String> = None;
236 let mut modified_at: Option<i64> = None;
237 let mut monitor_ids: Option<Vec<i64>> = None;
238 let mut monitor_tags: Option<Vec<String>> = None;
239 let mut name: Option<String> = None;
240 let mut query: Option<crate::datadogV1::model::ServiceLevelObjectiveQuery> = None;
241 let mut sli_specification: Option<crate::datadogV1::model::SLOSliSpec> = None;
242 let mut tags: Option<Vec<String>> = None;
243 let mut target_threshold: Option<f64> = None;
244 let mut thresholds: Option<Vec<crate::datadogV1::model::SLOThreshold>> = None;
245 let mut timeframe: Option<crate::datadogV1::model::SLOTimeframe> = None;
246 let mut type_: Option<crate::datadogV1::model::SLOType> = None;
247 let mut warning_threshold: Option<f64> = None;
248 let mut additional_properties: std::collections::BTreeMap<
249 String,
250 serde_json::Value,
251 > = std::collections::BTreeMap::new();
252 let mut _unparsed = false;
253
254 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
255 match k.as_str() {
256 "created_at" => {
257 if v.is_null() {
258 continue;
259 }
260 created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
261 }
262 "creator" => {
263 if v.is_null() {
264 continue;
265 }
266 creator = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
267 }
268 "description" => {
269 description =
270 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
271 }
272 "groups" => {
273 if v.is_null() {
274 continue;
275 }
276 groups = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
277 }
278 "id" => {
279 if v.is_null() {
280 continue;
281 }
282 id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
283 }
284 "modified_at" => {
285 if v.is_null() {
286 continue;
287 }
288 modified_at =
289 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
290 }
291 "monitor_ids" => {
292 if v.is_null() {
293 continue;
294 }
295 monitor_ids =
296 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
297 }
298 "monitor_tags" => {
299 if v.is_null() {
300 continue;
301 }
302 monitor_tags =
303 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
304 }
305 "name" => {
306 name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
307 }
308 "query" => {
309 if v.is_null() {
310 continue;
311 }
312 query = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
313 }
314 "sli_specification" => {
315 if v.is_null() {
316 continue;
317 }
318 sli_specification =
319 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
320 if let Some(ref _sli_specification) = sli_specification {
321 match _sli_specification {
322 crate::datadogV1::model::SLOSliSpec::UnparsedObject(
323 _sli_specification,
324 ) => {
325 _unparsed = true;
326 }
327 _ => {}
328 }
329 }
330 }
331 "tags" => {
332 if v.is_null() {
333 continue;
334 }
335 tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
336 }
337 "target_threshold" => {
338 if v.is_null() {
339 continue;
340 }
341 target_threshold =
342 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
343 }
344 "thresholds" => {
345 thresholds = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
346 }
347 "timeframe" => {
348 if v.is_null() {
349 continue;
350 }
351 timeframe = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
352 if let Some(ref _timeframe) = timeframe {
353 match _timeframe {
354 crate::datadogV1::model::SLOTimeframe::UnparsedObject(
355 _timeframe,
356 ) => {
357 _unparsed = true;
358 }
359 _ => {}
360 }
361 }
362 }
363 "type" => {
364 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
365 if let Some(ref _type_) = type_ {
366 match _type_ {
367 crate::datadogV1::model::SLOType::UnparsedObject(_type_) => {
368 _unparsed = true;
369 }
370 _ => {}
371 }
372 }
373 }
374 "warning_threshold" => {
375 if v.is_null() {
376 continue;
377 }
378 warning_threshold =
379 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
380 }
381 &_ => {
382 if let Ok(value) = serde_json::from_value(v.clone()) {
383 additional_properties.insert(k, value);
384 }
385 }
386 }
387 }
388 let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
389 let thresholds = thresholds.ok_or_else(|| M::Error::missing_field("thresholds"))?;
390 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
391
392 let content = ServiceLevelObjective {
393 created_at,
394 creator,
395 description,
396 groups,
397 id,
398 modified_at,
399 monitor_ids,
400 monitor_tags,
401 name,
402 query,
403 sli_specification,
404 tags,
405 target_threshold,
406 thresholds,
407 timeframe,
408 type_,
409 warning_threshold,
410 additional_properties,
411 _unparsed,
412 };
413
414 Ok(content)
415 }
416 }
417
418 deserializer.deserialize_any(ServiceLevelObjectiveVisitor)
419 }
420}