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 WorkflowDataAttributes {
#[serde(rename = "createdAt")]
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
#[serde(rename = "description")]
pub description: Option<String>,
#[serde(rename = "name")]
pub name: String,
#[serde(rename = "published")]
pub published: Option<bool>,
#[serde(rename = "spec")]
pub spec: crate::datadogV2::model::Spec,
#[serde(rename = "tags")]
pub tags: Option<Vec<String>>,
#[serde(rename = "updatedAt")]
pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
#[serde(rename = "webhookSecret")]
pub webhook_secret: Option<String>,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}
impl WorkflowDataAttributes {
pub fn new(name: String, spec: crate::datadogV2::model::Spec) -> WorkflowDataAttributes {
WorkflowDataAttributes {
created_at: None,
description: None,
name,
published: None,
spec,
tags: None,
updated_at: None,
webhook_secret: None,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}
pub fn created_at(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.created_at = Some(value);
self
}
pub fn description(mut self, value: String) -> Self {
self.description = Some(value);
self
}
pub fn published(mut self, value: bool) -> Self {
self.published = Some(value);
self
}
pub fn tags(mut self, value: Vec<String>) -> Self {
self.tags = Some(value);
self
}
pub fn updated_at(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.updated_at = Some(value);
self
}
pub fn webhook_secret(mut self, value: String) -> Self {
self.webhook_secret = Some(value);
self
}
pub fn additional_properties(
mut self,
value: std::collections::BTreeMap<String, serde_json::Value>,
) -> Self {
self.additional_properties = value;
self
}
}
impl<'de> Deserialize<'de> for WorkflowDataAttributes {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct WorkflowDataAttributesVisitor;
impl<'a> Visitor<'a> for WorkflowDataAttributesVisitor {
type Value = WorkflowDataAttributes;
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 created_at: Option<chrono::DateTime<chrono::Utc>> = None;
let mut description: Option<String> = None;
let mut name: Option<String> = None;
let mut published: Option<bool> = None;
let mut spec: Option<crate::datadogV2::model::Spec> = None;
let mut tags: Option<Vec<String>> = None;
let mut updated_at: Option<chrono::DateTime<chrono::Utc>> = None;
let mut webhook_secret: Option<String> = 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() {
"createdAt" => {
if v.is_null() {
continue;
}
created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"description" => {
if v.is_null() {
continue;
}
description =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"name" => {
name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"published" => {
if v.is_null() {
continue;
}
published = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"spec" => {
spec = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"tags" => {
if v.is_null() {
continue;
}
tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"updatedAt" => {
if v.is_null() {
continue;
}
updated_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"webhookSecret" => {
if v.is_null() {
continue;
}
webhook_secret =
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 name = name.ok_or_else(|| M::Error::missing_field("name"))?;
let spec = spec.ok_or_else(|| M::Error::missing_field("spec"))?;
let content = WorkflowDataAttributes {
created_at,
description,
name,
published,
spec,
tags,
updated_at,
webhook_secret,
additional_properties,
_unparsed,
};
Ok(content)
}
}
deserializer.deserialize_any(WorkflowDataAttributesVisitor)
}
}