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