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