use serde::de::{Error, MapAccess, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
use serde_with::skip_serializing_none;
use std::fmt::{self, Formatter};
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct SyntheticsTestVersionAttributes {
#[serde(rename = "author")]
pub author: Option<crate::datadogV2::model::SyntheticsTestVersionAuthor>,
#[serde(rename = "change_metadata")]
pub change_metadata:
Option<Vec<crate::datadogV2::model::SyntheticsTestVersionChangeMetadataItem>>,
#[serde(rename = "payload")]
pub payload: Option<std::collections::BTreeMap<String, serde_json::Value>>,
#[serde(rename = "version_payload_created_at")]
pub version_payload_created_at: Option<chrono::DateTime<chrono::Utc>>,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}
impl SyntheticsTestVersionAttributes {
pub fn new() -> SyntheticsTestVersionAttributes {
SyntheticsTestVersionAttributes {
author: None,
change_metadata: None,
payload: None,
version_payload_created_at: None,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}
pub fn author(mut self, value: crate::datadogV2::model::SyntheticsTestVersionAuthor) -> Self {
self.author = Some(value);
self
}
pub fn change_metadata(
mut self,
value: Vec<crate::datadogV2::model::SyntheticsTestVersionChangeMetadataItem>,
) -> Self {
self.change_metadata = Some(value);
self
}
pub fn payload(mut self, value: std::collections::BTreeMap<String, serde_json::Value>) -> Self {
self.payload = Some(value);
self
}
pub fn version_payload_created_at(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.version_payload_created_at = Some(value);
self
}
pub fn additional_properties(
mut self,
value: std::collections::BTreeMap<String, serde_json::Value>,
) -> Self {
self.additional_properties = value;
self
}
}
impl Default for SyntheticsTestVersionAttributes {
fn default() -> Self {
Self::new()
}
}
impl<'de> Deserialize<'de> for SyntheticsTestVersionAttributes {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct SyntheticsTestVersionAttributesVisitor;
impl<'a> Visitor<'a> for SyntheticsTestVersionAttributesVisitor {
type Value = SyntheticsTestVersionAttributes;
fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("a mapping")
}
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
where
M: MapAccess<'a>,
{
let mut author: Option<crate::datadogV2::model::SyntheticsTestVersionAuthor> = None;
let mut change_metadata: Option<
Vec<crate::datadogV2::model::SyntheticsTestVersionChangeMetadataItem>,
> = None;
let mut payload: Option<std::collections::BTreeMap<String, serde_json::Value>> =
None;
let mut version_payload_created_at: Option<chrono::DateTime<chrono::Utc>> = None;
let mut additional_properties: std::collections::BTreeMap<
String,
serde_json::Value,
> = std::collections::BTreeMap::new();
let mut _unparsed = false;
while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
match k.as_str() {
"author" => {
if v.is_null() {
continue;
}
author = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"change_metadata" => {
if v.is_null() {
continue;
}
change_metadata =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"payload" => {
if v.is_null() {
continue;
}
payload = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"version_payload_created_at" => {
if v.is_null() {
continue;
}
version_payload_created_at =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
&_ => {
if let Ok(value) = serde_json::from_value(v.clone()) {
additional_properties.insert(k, value);
}
}
}
}
let content = SyntheticsTestVersionAttributes {
author,
change_metadata,
payload,
version_payload_created_at,
additional_properties,
_unparsed,
};
Ok(content)
}
}
deserializer.deserialize_any(SyntheticsTestVersionAttributesVisitor)
}
}