datadog_api_client/datadogV2/model/
model_create_page_request_data_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/// Details about the On-Call Page you want to create.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct CreatePageRequestDataAttributes {
14    /// A short summary of the issue or context.
15    #[serde(rename = "description")]
16    pub description: Option<String>,
17    /// Tags to help categorize or filter the page.
18    #[serde(rename = "tags")]
19    pub tags: Option<Vec<String>>,
20    /// Information about the target to notify (such as a team or user).
21    #[serde(rename = "target")]
22    pub target: crate::datadogV2::model::CreatePageRequestDataAttributesTarget,
23    /// The title of the page.
24    #[serde(rename = "title")]
25    pub title: String,
26    /// On-Call Page urgency level.
27    #[serde(rename = "urgency")]
28    pub urgency: crate::datadogV2::model::PageUrgency,
29    #[serde(flatten)]
30    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
31    #[serde(skip)]
32    #[serde(default)]
33    pub(crate) _unparsed: bool,
34}
35
36impl CreatePageRequestDataAttributes {
37    pub fn new(
38        target: crate::datadogV2::model::CreatePageRequestDataAttributesTarget,
39        title: String,
40        urgency: crate::datadogV2::model::PageUrgency,
41    ) -> CreatePageRequestDataAttributes {
42        CreatePageRequestDataAttributes {
43            description: None,
44            tags: None,
45            target,
46            title,
47            urgency,
48            additional_properties: std::collections::BTreeMap::new(),
49            _unparsed: false,
50        }
51    }
52
53    pub fn description(mut self, value: String) -> Self {
54        self.description = Some(value);
55        self
56    }
57
58    pub fn tags(mut self, value: Vec<String>) -> Self {
59        self.tags = Some(value);
60        self
61    }
62
63    pub fn additional_properties(
64        mut self,
65        value: std::collections::BTreeMap<String, serde_json::Value>,
66    ) -> Self {
67        self.additional_properties = value;
68        self
69    }
70}
71
72impl<'de> Deserialize<'de> for CreatePageRequestDataAttributes {
73    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
74    where
75        D: Deserializer<'de>,
76    {
77        struct CreatePageRequestDataAttributesVisitor;
78        impl<'a> Visitor<'a> for CreatePageRequestDataAttributesVisitor {
79            type Value = CreatePageRequestDataAttributes;
80
81            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
82                f.write_str("a mapping")
83            }
84
85            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
86            where
87                M: MapAccess<'a>,
88            {
89                let mut description: Option<String> = None;
90                let mut tags: Option<Vec<String>> = None;
91                let mut target: Option<
92                    crate::datadogV2::model::CreatePageRequestDataAttributesTarget,
93                > = None;
94                let mut title: Option<String> = None;
95                let mut urgency: Option<crate::datadogV2::model::PageUrgency> = None;
96                let mut additional_properties: std::collections::BTreeMap<
97                    String,
98                    serde_json::Value,
99                > = std::collections::BTreeMap::new();
100                let mut _unparsed = false;
101
102                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
103                    match k.as_str() {
104                        "description" => {
105                            if v.is_null() {
106                                continue;
107                            }
108                            description =
109                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
110                        }
111                        "tags" => {
112                            if v.is_null() {
113                                continue;
114                            }
115                            tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
116                        }
117                        "target" => {
118                            target = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
119                        }
120                        "title" => {
121                            title = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
122                        }
123                        "urgency" => {
124                            urgency = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
125                            if let Some(ref _urgency) = urgency {
126                                match _urgency {
127                                    crate::datadogV2::model::PageUrgency::UnparsedObject(
128                                        _urgency,
129                                    ) => {
130                                        _unparsed = true;
131                                    }
132                                    _ => {}
133                                }
134                            }
135                        }
136                        &_ => {
137                            if let Ok(value) = serde_json::from_value(v.clone()) {
138                                additional_properties.insert(k, value);
139                            }
140                        }
141                    }
142                }
143                let target = target.ok_or_else(|| M::Error::missing_field("target"))?;
144                let title = title.ok_or_else(|| M::Error::missing_field("title"))?;
145                let urgency = urgency.ok_or_else(|| M::Error::missing_field("urgency"))?;
146
147                let content = CreatePageRequestDataAttributes {
148                    description,
149                    tags,
150                    target,
151                    title,
152                    urgency,
153                    additional_properties,
154                    _unparsed,
155                };
156
157                Ok(content)
158            }
159        }
160
161        deserializer.deserialize_any(CreatePageRequestDataAttributesVisitor)
162    }
163}