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 ReportScheduleResponseAttributes {
#[serde(
rename = "delivery_format",
default,
with = "::serde_with::rust::double_option"
)]
pub delivery_format:
Option<Option<crate::datadogV2::model::ReportScheduleResponseAttributesDeliveryFormat>>,
#[serde(rename = "description")]
pub description: String,
#[serialize_always]
#[serde(rename = "next_recurrence")]
pub next_recurrence: Option<i64>,
#[serde(rename = "recipients")]
pub recipients: Vec<String>,
#[serde(rename = "resource_id")]
pub resource_id: String,
#[serde(rename = "resource_type")]
pub resource_type: crate::datadogV2::model::ReportScheduleResourceType,
#[serde(rename = "rrule")]
pub rrule: String,
#[serde(rename = "status")]
pub status: crate::datadogV2::model::ReportScheduleStatus,
#[serialize_always]
#[serde(rename = "tab_id")]
pub tab_id: Option<String>,
#[serde(rename = "template_variables")]
pub template_variables: Vec<crate::datadogV2::model::ReportScheduleTemplateVariable>,
#[serialize_always]
#[serde(rename = "timeframe")]
pub timeframe: Option<String>,
#[serde(rename = "timezone")]
pub timezone: String,
#[serde(rename = "title")]
pub title: String,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}
impl ReportScheduleResponseAttributes {
pub fn new(
description: String,
next_recurrence: Option<i64>,
recipients: Vec<String>,
resource_id: String,
resource_type: crate::datadogV2::model::ReportScheduleResourceType,
rrule: String,
status: crate::datadogV2::model::ReportScheduleStatus,
tab_id: Option<String>,
template_variables: Vec<crate::datadogV2::model::ReportScheduleTemplateVariable>,
timeframe: Option<String>,
timezone: String,
title: String,
) -> ReportScheduleResponseAttributes {
ReportScheduleResponseAttributes {
delivery_format: None,
description,
next_recurrence,
recipients,
resource_id,
resource_type,
rrule,
status,
tab_id,
template_variables,
timeframe,
timezone,
title,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}
pub fn delivery_format(
mut self,
value: Option<crate::datadogV2::model::ReportScheduleResponseAttributesDeliveryFormat>,
) -> Self {
self.delivery_format = 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 ReportScheduleResponseAttributes {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct ReportScheduleResponseAttributesVisitor;
impl<'a> Visitor<'a> for ReportScheduleResponseAttributesVisitor {
type Value = ReportScheduleResponseAttributes;
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 delivery_format: Option<
Option<crate::datadogV2::model::ReportScheduleResponseAttributesDeliveryFormat>,
> = None;
let mut description: Option<String> = None;
let mut next_recurrence: Option<Option<i64>> = None;
let mut recipients: Option<Vec<String>> = None;
let mut resource_id: Option<String> = None;
let mut resource_type: Option<crate::datadogV2::model::ReportScheduleResourceType> =
None;
let mut rrule: Option<String> = None;
let mut status: Option<crate::datadogV2::model::ReportScheduleStatus> = None;
let mut tab_id: Option<Option<String>> = None;
let mut template_variables: Option<
Vec<crate::datadogV2::model::ReportScheduleTemplateVariable>,
> = None;
let mut timeframe: Option<Option<String>> = None;
let mut timezone: Option<String> = None;
let mut title: 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() {
"delivery_format" => {
delivery_format =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
if let Some(ref _delivery_format) = delivery_format {
match _delivery_format {
Some(crate::datadogV2::model::ReportScheduleResponseAttributesDeliveryFormat::UnparsedObject(_delivery_format)) => {
_unparsed = true;
},
_ => {}
}
}
}
"description" => {
description =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"next_recurrence" => {
next_recurrence =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"recipients" => {
recipients = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"resource_id" => {
resource_id =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"resource_type" => {
resource_type =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
if let Some(ref _resource_type) = resource_type {
match _resource_type {
crate::datadogV2::model::ReportScheduleResourceType::UnparsedObject(_resource_type) => {
_unparsed = true;
},
_ => {}
}
}
}
"rrule" => {
rrule = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"status" => {
status = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
if let Some(ref _status) = status {
match _status {
crate::datadogV2::model::ReportScheduleStatus::UnparsedObject(_status) => {
_unparsed = true;
},
_ => {}
}
}
}
"tab_id" => {
tab_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"template_variables" => {
template_variables =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"timeframe" => {
timeframe = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"timezone" => {
timezone = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"title" => {
title = 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 description =
description.ok_or_else(|| M::Error::missing_field("description"))?;
let next_recurrence =
next_recurrence.ok_or_else(|| M::Error::missing_field("next_recurrence"))?;
let recipients = recipients.ok_or_else(|| M::Error::missing_field("recipients"))?;
let resource_id =
resource_id.ok_or_else(|| M::Error::missing_field("resource_id"))?;
let resource_type =
resource_type.ok_or_else(|| M::Error::missing_field("resource_type"))?;
let rrule = rrule.ok_or_else(|| M::Error::missing_field("rrule"))?;
let status = status.ok_or_else(|| M::Error::missing_field("status"))?;
let tab_id = tab_id.ok_or_else(|| M::Error::missing_field("tab_id"))?;
let template_variables = template_variables
.ok_or_else(|| M::Error::missing_field("template_variables"))?;
let timeframe = timeframe.ok_or_else(|| M::Error::missing_field("timeframe"))?;
let timezone = timezone.ok_or_else(|| M::Error::missing_field("timezone"))?;
let title = title.ok_or_else(|| M::Error::missing_field("title"))?;
let content = ReportScheduleResponseAttributes {
delivery_format,
description,
next_recurrence,
recipients,
resource_id,
resource_type,
rrule,
status,
tab_id,
template_variables,
timeframe,
timezone,
title,
additional_properties,
_unparsed,
};
Ok(content)
}
}
deserializer.deserialize_any(ReportScheduleResponseAttributesVisitor)
}
}