datadog_api_client/datadogV2/model/
model_patch_notification_rule_parameters_data.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/// Data of the notification rule patch request: the rule ID, the rule type, and the rule attributes. All fields are required.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct PatchNotificationRuleParametersData {
14    /// Attributes of the notification rule patch request. It is required to update the version of the rule when patching it.
15    #[serde(rename = "attributes")]
16    pub attributes: crate::datadogV2::model::PatchNotificationRuleParametersDataAttributes,
17    /// The ID of a notification rule.
18    #[serde(rename = "id")]
19    pub id: String,
20    /// The rule type associated to notification rules.
21    #[serde(rename = "type")]
22    pub type_: crate::datadogV2::model::NotificationRulesType,
23    #[serde(flatten)]
24    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
25    #[serde(skip)]
26    #[serde(default)]
27    pub(crate) _unparsed: bool,
28}
29
30impl PatchNotificationRuleParametersData {
31    pub fn new(
32        attributes: crate::datadogV2::model::PatchNotificationRuleParametersDataAttributes,
33        id: String,
34        type_: crate::datadogV2::model::NotificationRulesType,
35    ) -> PatchNotificationRuleParametersData {
36        PatchNotificationRuleParametersData {
37            attributes,
38            id,
39            type_,
40            additional_properties: std::collections::BTreeMap::new(),
41            _unparsed: false,
42        }
43    }
44
45    pub fn additional_properties(
46        mut self,
47        value: std::collections::BTreeMap<String, serde_json::Value>,
48    ) -> Self {
49        self.additional_properties = value;
50        self
51    }
52}
53
54impl<'de> Deserialize<'de> for PatchNotificationRuleParametersData {
55    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
56    where
57        D: Deserializer<'de>,
58    {
59        struct PatchNotificationRuleParametersDataVisitor;
60        impl<'a> Visitor<'a> for PatchNotificationRuleParametersDataVisitor {
61            type Value = PatchNotificationRuleParametersData;
62
63            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
64                f.write_str("a mapping")
65            }
66
67            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
68            where
69                M: MapAccess<'a>,
70            {
71                let mut attributes: Option<
72                    crate::datadogV2::model::PatchNotificationRuleParametersDataAttributes,
73                > = None;
74                let mut id: Option<String> = None;
75                let mut type_: Option<crate::datadogV2::model::NotificationRulesType> = None;
76                let mut additional_properties: std::collections::BTreeMap<
77                    String,
78                    serde_json::Value,
79                > = std::collections::BTreeMap::new();
80                let mut _unparsed = false;
81
82                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
83                    match k.as_str() {
84                        "attributes" => {
85                            attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
86                        }
87                        "id" => {
88                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
89                        }
90                        "type" => {
91                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
92                            if let Some(ref _type_) = type_ {
93                                match _type_ {
94                                    crate::datadogV2::model::NotificationRulesType::UnparsedObject(_type_) => {
95                                        _unparsed = true;
96                                    },
97                                    _ => {}
98                                }
99                            }
100                        }
101                        &_ => {
102                            if let Ok(value) = serde_json::from_value(v.clone()) {
103                                additional_properties.insert(k, value);
104                            }
105                        }
106                    }
107                }
108                let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?;
109                let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
110                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
111
112                let content = PatchNotificationRuleParametersData {
113                    attributes,
114                    id,
115                    type_,
116                    additional_properties,
117                    _unparsed,
118                };
119
120                Ok(content)
121            }
122        }
123
124        deserializer.deserialize_any(PatchNotificationRuleParametersDataVisitor)
125    }
126}