datadog_api_client/datadogV1/model/
model_notebook_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 attributes of a notebook.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct NotebookResponseDataAttributes {
14    /// Attributes of user object returned by the API.
15    #[serde(rename = "author")]
16    pub author: Option<crate::datadogV1::model::NotebookAuthor>,
17    /// List of cells to display in the notebook.
18    #[serde(rename = "cells")]
19    pub cells: Vec<crate::datadogV1::model::NotebookCellResponse>,
20    /// UTC time stamp for when the notebook was created.
21    #[serde(rename = "created")]
22    pub created: Option<chrono::DateTime<chrono::Utc>>,
23    /// Metadata associated with the notebook.
24    #[serde(rename = "metadata")]
25    pub metadata: Option<crate::datadogV1::model::NotebookMetadata>,
26    /// UTC time stamp for when the notebook was last modified.
27    #[serde(rename = "modified")]
28    pub modified: Option<chrono::DateTime<chrono::Utc>>,
29    /// The name of the notebook.
30    #[serde(rename = "name")]
31    pub name: String,
32    /// Publication status of the notebook. For now, always "published".
33    #[serde(rename = "status")]
34    pub status: Option<crate::datadogV1::model::NotebookStatus>,
35    /// Notebook global timeframe.
36    #[serde(rename = "time")]
37    pub time: crate::datadogV1::model::NotebookGlobalTime,
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 NotebookResponseDataAttributes {
46    pub fn new(
47        cells: Vec<crate::datadogV1::model::NotebookCellResponse>,
48        name: String,
49        time: crate::datadogV1::model::NotebookGlobalTime,
50    ) -> NotebookResponseDataAttributes {
51        NotebookResponseDataAttributes {
52            author: None,
53            cells,
54            created: None,
55            metadata: None,
56            modified: None,
57            name,
58            status: None,
59            time,
60            additional_properties: std::collections::BTreeMap::new(),
61            _unparsed: false,
62        }
63    }
64
65    pub fn author(mut self, value: crate::datadogV1::model::NotebookAuthor) -> Self {
66        self.author = Some(value);
67        self
68    }
69
70    pub fn created(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
71        self.created = Some(value);
72        self
73    }
74
75    pub fn metadata(mut self, value: crate::datadogV1::model::NotebookMetadata) -> Self {
76        self.metadata = Some(value);
77        self
78    }
79
80    pub fn modified(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
81        self.modified = Some(value);
82        self
83    }
84
85    pub fn status(mut self, value: crate::datadogV1::model::NotebookStatus) -> Self {
86        self.status = Some(value);
87        self
88    }
89
90    pub fn additional_properties(
91        mut self,
92        value: std::collections::BTreeMap<String, serde_json::Value>,
93    ) -> Self {
94        self.additional_properties = value;
95        self
96    }
97}
98
99impl<'de> Deserialize<'de> for NotebookResponseDataAttributes {
100    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
101    where
102        D: Deserializer<'de>,
103    {
104        struct NotebookResponseDataAttributesVisitor;
105        impl<'a> Visitor<'a> for NotebookResponseDataAttributesVisitor {
106            type Value = NotebookResponseDataAttributes;
107
108            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
109                f.write_str("a mapping")
110            }
111
112            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
113            where
114                M: MapAccess<'a>,
115            {
116                let mut author: Option<crate::datadogV1::model::NotebookAuthor> = None;
117                let mut cells: Option<Vec<crate::datadogV1::model::NotebookCellResponse>> = None;
118                let mut created: Option<chrono::DateTime<chrono::Utc>> = None;
119                let mut metadata: Option<crate::datadogV1::model::NotebookMetadata> = None;
120                let mut modified: Option<chrono::DateTime<chrono::Utc>> = None;
121                let mut name: Option<String> = None;
122                let mut status: Option<crate::datadogV1::model::NotebookStatus> = None;
123                let mut time: Option<crate::datadogV1::model::NotebookGlobalTime> = None;
124                let mut additional_properties: std::collections::BTreeMap<
125                    String,
126                    serde_json::Value,
127                > = std::collections::BTreeMap::new();
128                let mut _unparsed = false;
129
130                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
131                    match k.as_str() {
132                        "author" => {
133                            if v.is_null() {
134                                continue;
135                            }
136                            author = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
137                        }
138                        "cells" => {
139                            cells = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
140                        }
141                        "created" => {
142                            if v.is_null() {
143                                continue;
144                            }
145                            created = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
146                        }
147                        "metadata" => {
148                            if v.is_null() {
149                                continue;
150                            }
151                            metadata = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
152                        }
153                        "modified" => {
154                            if v.is_null() {
155                                continue;
156                            }
157                            modified = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
158                        }
159                        "name" => {
160                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
161                        }
162                        "status" => {
163                            if v.is_null() {
164                                continue;
165                            }
166                            status = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
167                            if let Some(ref _status) = status {
168                                match _status {
169                                    crate::datadogV1::model::NotebookStatus::UnparsedObject(
170                                        _status,
171                                    ) => {
172                                        _unparsed = true;
173                                    }
174                                    _ => {}
175                                }
176                            }
177                        }
178                        "time" => {
179                            time = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
180                            if let Some(ref _time) = time {
181                                match _time {
182                                    crate::datadogV1::model::NotebookGlobalTime::UnparsedObject(
183                                        _time,
184                                    ) => {
185                                        _unparsed = true;
186                                    }
187                                    _ => {}
188                                }
189                            }
190                        }
191                        &_ => {
192                            if let Ok(value) = serde_json::from_value(v.clone()) {
193                                additional_properties.insert(k, value);
194                            }
195                        }
196                    }
197                }
198                let cells = cells.ok_or_else(|| M::Error::missing_field("cells"))?;
199                let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
200                let time = time.ok_or_else(|| M::Error::missing_field("time"))?;
201
202                let content = NotebookResponseDataAttributes {
203                    author,
204                    cells,
205                    created,
206                    metadata,
207                    modified,
208                    name,
209                    status,
210                    time,
211                    additional_properties,
212                    _unparsed,
213                };
214
215                Ok(content)
216            }
217        }
218
219        deserializer.deserialize_any(NotebookResponseDataAttributesVisitor)
220    }
221}