datadog_api_client/datadogV2/model/
model_incident_notification_rule_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 IncidentNotificationRuleCreateAttributes {
14    #[serde(rename = "conditions")]
16    pub conditions: Vec<crate::datadogV2::model::IncidentNotificationRuleConditionsItems>,
17    #[serde(rename = "enabled")]
19    pub enabled: Option<bool>,
20    #[serde(rename = "handles")]
22    pub handles: Vec<String>,
23    #[serde(rename = "renotify_on")]
25    pub renotify_on: Option<Vec<String>>,
26    #[serde(rename = "trigger")]
28    pub trigger: String,
29    #[serde(rename = "visibility")]
31    pub visibility:
32        Option<crate::datadogV2::model::IncidentNotificationRuleCreateAttributesVisibility>,
33    #[serde(flatten)]
34    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
35    #[serde(skip)]
36    #[serde(default)]
37    pub(crate) _unparsed: bool,
38}
39
40impl IncidentNotificationRuleCreateAttributes {
41    pub fn new(
42        conditions: Vec<crate::datadogV2::model::IncidentNotificationRuleConditionsItems>,
43        handles: Vec<String>,
44        trigger: String,
45    ) -> IncidentNotificationRuleCreateAttributes {
46        IncidentNotificationRuleCreateAttributes {
47            conditions,
48            enabled: None,
49            handles,
50            renotify_on: None,
51            trigger,
52            visibility: None,
53            additional_properties: std::collections::BTreeMap::new(),
54            _unparsed: false,
55        }
56    }
57
58    pub fn enabled(mut self, value: bool) -> Self {
59        self.enabled = Some(value);
60        self
61    }
62
63    pub fn renotify_on(mut self, value: Vec<String>) -> Self {
64        self.renotify_on = Some(value);
65        self
66    }
67
68    pub fn visibility(
69        mut self,
70        value: crate::datadogV2::model::IncidentNotificationRuleCreateAttributesVisibility,
71    ) -> Self {
72        self.visibility = Some(value);
73        self
74    }
75
76    pub fn additional_properties(
77        mut self,
78        value: std::collections::BTreeMap<String, serde_json::Value>,
79    ) -> Self {
80        self.additional_properties = value;
81        self
82    }
83}
84
85impl<'de> Deserialize<'de> for IncidentNotificationRuleCreateAttributes {
86    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
87    where
88        D: Deserializer<'de>,
89    {
90        struct IncidentNotificationRuleCreateAttributesVisitor;
91        impl<'a> Visitor<'a> for IncidentNotificationRuleCreateAttributesVisitor {
92            type Value = IncidentNotificationRuleCreateAttributes;
93
94            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
95                f.write_str("a mapping")
96            }
97
98            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
99            where
100                M: MapAccess<'a>,
101            {
102                let mut conditions: Option<
103                    Vec<crate::datadogV2::model::IncidentNotificationRuleConditionsItems>,
104                > = None;
105                let mut enabled: Option<bool> = None;
106                let mut handles: Option<Vec<String>> = None;
107                let mut renotify_on: Option<Vec<String>> = None;
108                let mut trigger: Option<String> = None;
109                let mut visibility: Option<
110                    crate::datadogV2::model::IncidentNotificationRuleCreateAttributesVisibility,
111                > = None;
112                let mut additional_properties: std::collections::BTreeMap<
113                    String,
114                    serde_json::Value,
115                > = std::collections::BTreeMap::new();
116                let mut _unparsed = false;
117
118                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
119                    match k.as_str() {
120                        "conditions" => {
121                            conditions = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
122                        }
123                        "enabled" => {
124                            if v.is_null() {
125                                continue;
126                            }
127                            enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
128                        }
129                        "handles" => {
130                            handles = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
131                        }
132                        "renotify_on" => {
133                            if v.is_null() {
134                                continue;
135                            }
136                            renotify_on =
137                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
138                        }
139                        "trigger" => {
140                            trigger = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
141                        }
142                        "visibility" => {
143                            if v.is_null() {
144                                continue;
145                            }
146                            visibility = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
147                            if let Some(ref _visibility) = visibility {
148                                match _visibility {
149                                    crate::datadogV2::model::IncidentNotificationRuleCreateAttributesVisibility::UnparsedObject(_visibility) => {
150                                        _unparsed = true;
151                                    },
152                                    _ => {}
153                                }
154                            }
155                        }
156                        &_ => {
157                            if let Ok(value) = serde_json::from_value(v.clone()) {
158                                additional_properties.insert(k, value);
159                            }
160                        }
161                    }
162                }
163                let conditions = conditions.ok_or_else(|| M::Error::missing_field("conditions"))?;
164                let handles = handles.ok_or_else(|| M::Error::missing_field("handles"))?;
165                let trigger = trigger.ok_or_else(|| M::Error::missing_field("trigger"))?;
166
167                let content = IncidentNotificationRuleCreateAttributes {
168                    conditions,
169                    enabled,
170                    handles,
171                    renotify_on,
172                    trigger,
173                    visibility,
174                    additional_properties,
175                    _unparsed,
176                };
177
178                Ok(content)
179            }
180        }
181
182        deserializer.deserialize_any(IncidentNotificationRuleCreateAttributesVisitor)
183    }
184}