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 IncidentUpdateAttributes {
#[serde(
rename = "customer_impact_end",
default,
with = "::serde_with::rust::double_option"
)]
pub customer_impact_end: Option<Option<chrono::DateTime<chrono::Utc>>>,
#[serde(rename = "customer_impact_scope")]
pub customer_impact_scope: Option<String>,
#[serde(
rename = "customer_impact_start",
default,
with = "::serde_with::rust::double_option"
)]
pub customer_impact_start: Option<Option<chrono::DateTime<chrono::Utc>>>,
#[serde(rename = "customer_impacted")]
pub customer_impacted: Option<bool>,
#[serde(
rename = "detected",
default,
with = "::serde_with::rust::double_option"
)]
pub detected: Option<Option<chrono::DateTime<chrono::Utc>>>,
#[serde(rename = "fields")]
pub fields: Option<
std::collections::BTreeMap<String, crate::datadogV2::model::IncidentFieldAttributes>,
>,
#[serde(rename = "notification_handles")]
pub notification_handles: Option<Vec<crate::datadogV2::model::IncidentNotificationHandle>>,
#[serde(rename = "title")]
pub title: Option<String>,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}
impl IncidentUpdateAttributes {
pub fn new() -> IncidentUpdateAttributes {
IncidentUpdateAttributes {
customer_impact_end: None,
customer_impact_scope: None,
customer_impact_start: None,
customer_impacted: None,
detected: None,
fields: None,
notification_handles: None,
title: None,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}
pub fn customer_impact_end(mut self, value: Option<chrono::DateTime<chrono::Utc>>) -> Self {
self.customer_impact_end = Some(value);
self
}
pub fn customer_impact_scope(mut self, value: String) -> Self {
self.customer_impact_scope = Some(value);
self
}
pub fn customer_impact_start(mut self, value: Option<chrono::DateTime<chrono::Utc>>) -> Self {
self.customer_impact_start = Some(value);
self
}
pub fn customer_impacted(mut self, value: bool) -> Self {
self.customer_impacted = Some(value);
self
}
pub fn detected(mut self, value: Option<chrono::DateTime<chrono::Utc>>) -> Self {
self.detected = Some(value);
self
}
pub fn fields(
mut self,
value: std::collections::BTreeMap<String, crate::datadogV2::model::IncidentFieldAttributes>,
) -> Self {
self.fields = Some(value);
self
}
pub fn notification_handles(
mut self,
value: Vec<crate::datadogV2::model::IncidentNotificationHandle>,
) -> Self {
self.notification_handles = Some(value);
self
}
pub fn title(mut self, value: String) -> Self {
self.title = 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 IncidentUpdateAttributes {
fn default() -> Self {
Self::new()
}
}
impl<'de> Deserialize<'de> for IncidentUpdateAttributes {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct IncidentUpdateAttributesVisitor;
impl<'a> Visitor<'a> for IncidentUpdateAttributesVisitor {
type Value = IncidentUpdateAttributes;
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 customer_impact_end: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
let mut customer_impact_scope: Option<String> = None;
let mut customer_impact_start: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
let mut customer_impacted: Option<bool> = None;
let mut detected: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
let mut fields: Option<
std::collections::BTreeMap<
String,
crate::datadogV2::model::IncidentFieldAttributes,
>,
> = None;
let mut notification_handles: Option<
Vec<crate::datadogV2::model::IncidentNotificationHandle>,
> = 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() {
"customer_impact_end" => {
customer_impact_end =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"customer_impact_scope" => {
if v.is_null() {
continue;
}
customer_impact_scope =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"customer_impact_start" => {
customer_impact_start =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"customer_impacted" => {
if v.is_null() {
continue;
}
customer_impacted =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"detected" => {
detected = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"fields" => {
if v.is_null() {
continue;
}
fields = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"notification_handles" => {
if v.is_null() {
continue;
}
notification_handles =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"title" => {
if v.is_null() {
continue;
}
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 content = IncidentUpdateAttributes {
customer_impact_end,
customer_impact_scope,
customer_impact_start,
customer_impacted,
detected,
fields,
notification_handles,
title,
additional_properties,
_unparsed,
};
Ok(content)
}
}
deserializer.deserialize_any(IncidentUpdateAttributesVisitor)
}
}