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 GovernanceConfigAttributes {
#[serde(rename = "assignment_notifications_enabled")]
pub assignment_notifications_enabled: bool,
#[serde(rename = "enabled")]
pub enabled: bool,
#[serde(rename = "usage_attribution_configured")]
pub usage_attribution_configured: bool,
#[serde(rename = "xorg_insights_enabled")]
pub xorg_insights_enabled: bool,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}
impl GovernanceConfigAttributes {
pub fn new(
assignment_notifications_enabled: bool,
enabled: bool,
usage_attribution_configured: bool,
xorg_insights_enabled: bool,
) -> GovernanceConfigAttributes {
GovernanceConfigAttributes {
assignment_notifications_enabled,
enabled,
usage_attribution_configured,
xorg_insights_enabled,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}
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 GovernanceConfigAttributes {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct GovernanceConfigAttributesVisitor;
impl<'a> Visitor<'a> for GovernanceConfigAttributesVisitor {
type Value = GovernanceConfigAttributes;
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 assignment_notifications_enabled: Option<bool> = None;
let mut enabled: Option<bool> = None;
let mut usage_attribution_configured: Option<bool> = None;
let mut xorg_insights_enabled: Option<bool> = 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() {
"assignment_notifications_enabled" => {
assignment_notifications_enabled =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"enabled" => {
enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"usage_attribution_configured" => {
usage_attribution_configured =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"xorg_insights_enabled" => {
xorg_insights_enabled =
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 assignment_notifications_enabled = assignment_notifications_enabled
.ok_or_else(|| M::Error::missing_field("assignment_notifications_enabled"))?;
let enabled = enabled.ok_or_else(|| M::Error::missing_field("enabled"))?;
let usage_attribution_configured = usage_attribution_configured
.ok_or_else(|| M::Error::missing_field("usage_attribution_configured"))?;
let xorg_insights_enabled = xorg_insights_enabled
.ok_or_else(|| M::Error::missing_field("xorg_insights_enabled"))?;
let content = GovernanceConfigAttributes {
assignment_notifications_enabled,
enabled,
usage_attribution_configured,
xorg_insights_enabled,
additional_properties,
_unparsed,
};
Ok(content)
}
}
deserializer.deserialize_any(GovernanceConfigAttributesVisitor)
}
}