datadog_api_client/datadogV2/model/
model_event_response_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 object description of an event response attribute.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct EventResponseAttributes {
14    /// Object description of attributes from your event.
15    #[serde(rename = "attributes")]
16    pub attributes: Option<crate::datadogV2::model::EventAttributes>,
17    /// The message of the event.
18    #[serde(rename = "message")]
19    pub message: Option<String>,
20    /// An array of tags associated with the event.
21    #[serde(rename = "tags")]
22    pub tags: Option<Vec<String>>,
23    /// The timestamp of the event.
24    #[serde(rename = "timestamp")]
25    pub timestamp: Option<chrono::DateTime<chrono::Utc>>,
26    #[serde(flatten)]
27    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
28    #[serde(skip)]
29    #[serde(default)]
30    pub(crate) _unparsed: bool,
31}
32
33impl EventResponseAttributes {
34    pub fn new() -> EventResponseAttributes {
35        EventResponseAttributes {
36            attributes: None,
37            message: None,
38            tags: None,
39            timestamp: None,
40            additional_properties: std::collections::BTreeMap::new(),
41            _unparsed: false,
42        }
43    }
44
45    pub fn attributes(mut self, value: crate::datadogV2::model::EventAttributes) -> Self {
46        self.attributes = Some(value);
47        self
48    }
49
50    pub fn message(mut self, value: String) -> Self {
51        self.message = Some(value);
52        self
53    }
54
55    pub fn tags(mut self, value: Vec<String>) -> Self {
56        self.tags = Some(value);
57        self
58    }
59
60    pub fn timestamp(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
61        self.timestamp = Some(value);
62        self
63    }
64
65    pub fn additional_properties(
66        mut self,
67        value: std::collections::BTreeMap<String, serde_json::Value>,
68    ) -> Self {
69        self.additional_properties = value;
70        self
71    }
72}
73
74impl Default for EventResponseAttributes {
75    fn default() -> Self {
76        Self::new()
77    }
78}
79
80impl<'de> Deserialize<'de> for EventResponseAttributes {
81    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
82    where
83        D: Deserializer<'de>,
84    {
85        struct EventResponseAttributesVisitor;
86        impl<'a> Visitor<'a> for EventResponseAttributesVisitor {
87            type Value = EventResponseAttributes;
88
89            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
90                f.write_str("a mapping")
91            }
92
93            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
94            where
95                M: MapAccess<'a>,
96            {
97                let mut attributes: Option<crate::datadogV2::model::EventAttributes> = None;
98                let mut message: Option<String> = None;
99                let mut tags: Option<Vec<String>> = None;
100                let mut timestamp: Option<chrono::DateTime<chrono::Utc>> = None;
101                let mut additional_properties: std::collections::BTreeMap<
102                    String,
103                    serde_json::Value,
104                > = std::collections::BTreeMap::new();
105                let mut _unparsed = false;
106
107                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
108                    match k.as_str() {
109                        "attributes" => {
110                            if v.is_null() {
111                                continue;
112                            }
113                            attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
114                        }
115                        "message" => {
116                            if v.is_null() {
117                                continue;
118                            }
119                            message = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
120                        }
121                        "tags" => {
122                            if v.is_null() {
123                                continue;
124                            }
125                            tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
126                        }
127                        "timestamp" => {
128                            if v.is_null() {
129                                continue;
130                            }
131                            timestamp = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
132                        }
133                        &_ => {
134                            if let Ok(value) = serde_json::from_value(v.clone()) {
135                                additional_properties.insert(k, value);
136                            }
137                        }
138                    }
139                }
140
141                let content = EventResponseAttributes {
142                    attributes,
143                    message,
144                    tags,
145                    timestamp,
146                    additional_properties,
147                    _unparsed,
148                };
149
150                Ok(content)
151            }
152        }
153
154        deserializer.deserialize_any(EventResponseAttributesVisitor)
155    }
156}