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 SignalsProblemsDetections {
#[serde(rename = "high_frozen_frame_rates")]
pub high_frozen_frame_rates:
Option<Vec<crate::datadogV2::model::AggregatedHighFrozenFrameRate>>,
#[serde(rename = "high_script_evaluations")]
pub high_script_evaluations: Option<Vec<crate::datadogV2::model::AggregatedHighScriptEval>>,
#[serde(rename = "low_cache_hit_rates")]
pub low_cache_hit_rates: Option<Vec<crate::datadogV2::model::AggregatedLowCacheHitRate>>,
#[serde(rename = "mobile_scroll_frictions")]
pub mobile_scroll_frictions:
Option<Vec<crate::datadogV2::model::AggregatedMobileScrollFriction>>,
#[serde(rename = "slow_fcp_high_bytes")]
pub slow_fcp_high_bytes: Option<Vec<crate::datadogV2::model::AggregatedSlowFCPHighBytes>>,
#[serde(rename = "slow_interaction_long_tasks")]
pub slow_interaction_long_tasks:
Option<Vec<crate::datadogV2::model::AggregatedSlowInteractionLongTask>>,
#[serde(rename = "uncompressed_resources")]
pub uncompressed_resources:
Option<Vec<crate::datadogV2::model::AggregatedUncompressedResource>>,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}
impl SignalsProblemsDetections {
pub fn new() -> SignalsProblemsDetections {
SignalsProblemsDetections {
high_frozen_frame_rates: None,
high_script_evaluations: None,
low_cache_hit_rates: None,
mobile_scroll_frictions: None,
slow_fcp_high_bytes: None,
slow_interaction_long_tasks: None,
uncompressed_resources: None,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}
pub fn high_frozen_frame_rates(
mut self,
value: Vec<crate::datadogV2::model::AggregatedHighFrozenFrameRate>,
) -> Self {
self.high_frozen_frame_rates = Some(value);
self
}
pub fn high_script_evaluations(
mut self,
value: Vec<crate::datadogV2::model::AggregatedHighScriptEval>,
) -> Self {
self.high_script_evaluations = Some(value);
self
}
pub fn low_cache_hit_rates(
mut self,
value: Vec<crate::datadogV2::model::AggregatedLowCacheHitRate>,
) -> Self {
self.low_cache_hit_rates = Some(value);
self
}
pub fn mobile_scroll_frictions(
mut self,
value: Vec<crate::datadogV2::model::AggregatedMobileScrollFriction>,
) -> Self {
self.mobile_scroll_frictions = Some(value);
self
}
pub fn slow_fcp_high_bytes(
mut self,
value: Vec<crate::datadogV2::model::AggregatedSlowFCPHighBytes>,
) -> Self {
self.slow_fcp_high_bytes = Some(value);
self
}
pub fn slow_interaction_long_tasks(
mut self,
value: Vec<crate::datadogV2::model::AggregatedSlowInteractionLongTask>,
) -> Self {
self.slow_interaction_long_tasks = Some(value);
self
}
pub fn uncompressed_resources(
mut self,
value: Vec<crate::datadogV2::model::AggregatedUncompressedResource>,
) -> Self {
self.uncompressed_resources = 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 SignalsProblemsDetections {
fn default() -> Self {
Self::new()
}
}
impl<'de> Deserialize<'de> for SignalsProblemsDetections {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct SignalsProblemsDetectionsVisitor;
impl<'a> Visitor<'a> for SignalsProblemsDetectionsVisitor {
type Value = SignalsProblemsDetections;
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 high_frozen_frame_rates: Option<
Vec<crate::datadogV2::model::AggregatedHighFrozenFrameRate>,
> = None;
let mut high_script_evaluations: Option<
Vec<crate::datadogV2::model::AggregatedHighScriptEval>,
> = None;
let mut low_cache_hit_rates: Option<
Vec<crate::datadogV2::model::AggregatedLowCacheHitRate>,
> = None;
let mut mobile_scroll_frictions: Option<
Vec<crate::datadogV2::model::AggregatedMobileScrollFriction>,
> = None;
let mut slow_fcp_high_bytes: Option<
Vec<crate::datadogV2::model::AggregatedSlowFCPHighBytes>,
> = None;
let mut slow_interaction_long_tasks: Option<
Vec<crate::datadogV2::model::AggregatedSlowInteractionLongTask>,
> = None;
let mut uncompressed_resources: Option<
Vec<crate::datadogV2::model::AggregatedUncompressedResource>,
> = 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() {
"high_frozen_frame_rates" => {
if v.is_null() {
continue;
}
high_frozen_frame_rates =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"high_script_evaluations" => {
if v.is_null() {
continue;
}
high_script_evaluations =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"low_cache_hit_rates" => {
if v.is_null() {
continue;
}
low_cache_hit_rates =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"mobile_scroll_frictions" => {
if v.is_null() {
continue;
}
mobile_scroll_frictions =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"slow_fcp_high_bytes" => {
if v.is_null() {
continue;
}
slow_fcp_high_bytes =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"slow_interaction_long_tasks" => {
if v.is_null() {
continue;
}
slow_interaction_long_tasks =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"uncompressed_resources" => {
if v.is_null() {
continue;
}
uncompressed_resources =
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 = SignalsProblemsDetections {
high_frozen_frame_rates,
high_script_evaluations,
low_cache_hit_rates,
mobile_scroll_frictions,
slow_fcp_high_bytes,
slow_interaction_long_tasks,
uncompressed_resources,
additional_properties,
_unparsed,
};
Ok(content)
}
}
deserializer.deserialize_any(SignalsProblemsDetectionsVisitor)
}
}