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 IPRanges {
#[serde(rename = "agents")]
pub agents: Option<crate::datadogV1::model::IPPrefixesAgents>,
#[serde(rename = "api")]
pub api: Option<crate::datadogV1::model::IPPrefixesAPI>,
#[serde(rename = "apm")]
pub apm: Option<crate::datadogV1::model::IPPrefixesAPM>,
#[serde(rename = "global")]
pub global: Option<crate::datadogV1::model::IPPrefixesGlobal>,
#[serde(rename = "logs")]
pub logs: Option<crate::datadogV1::model::IPPrefixesLogs>,
#[serde(rename = "modified")]
pub modified: Option<String>,
#[serde(rename = "orchestrator")]
pub orchestrator: Option<crate::datadogV1::model::IPPrefixesOrchestrator>,
#[serde(rename = "process")]
pub process: Option<crate::datadogV1::model::IPPrefixesProcess>,
#[serde(rename = "remote-configuration")]
pub remote_configuration: Option<crate::datadogV1::model::IPPrefixesRemoteConfiguration>,
#[serde(rename = "synthetics")]
pub synthetics: Option<crate::datadogV1::model::IPPrefixesSynthetics>,
#[serde(rename = "synthetics-private-locations")]
pub synthetics_private_locations:
Option<crate::datadogV1::model::IPPrefixesSyntheticsPrivateLocations>,
#[serde(rename = "version")]
pub version: Option<i64>,
#[serde(rename = "webhooks")]
pub webhooks: Option<crate::datadogV1::model::IPPrefixesWebhooks>,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}
impl IPRanges {
pub fn new() -> IPRanges {
IPRanges {
agents: None,
api: None,
apm: None,
global: None,
logs: None,
modified: None,
orchestrator: None,
process: None,
remote_configuration: None,
synthetics: None,
synthetics_private_locations: None,
version: None,
webhooks: None,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}
pub fn agents(mut self, value: crate::datadogV1::model::IPPrefixesAgents) -> Self {
self.agents = Some(value);
self
}
pub fn api(mut self, value: crate::datadogV1::model::IPPrefixesAPI) -> Self {
self.api = Some(value);
self
}
pub fn apm(mut self, value: crate::datadogV1::model::IPPrefixesAPM) -> Self {
self.apm = Some(value);
self
}
pub fn global(mut self, value: crate::datadogV1::model::IPPrefixesGlobal) -> Self {
self.global = Some(value);
self
}
pub fn logs(mut self, value: crate::datadogV1::model::IPPrefixesLogs) -> Self {
self.logs = Some(value);
self
}
pub fn modified(mut self, value: String) -> Self {
self.modified = Some(value);
self
}
pub fn orchestrator(mut self, value: crate::datadogV1::model::IPPrefixesOrchestrator) -> Self {
self.orchestrator = Some(value);
self
}
pub fn process(mut self, value: crate::datadogV1::model::IPPrefixesProcess) -> Self {
self.process = Some(value);
self
}
pub fn remote_configuration(
mut self,
value: crate::datadogV1::model::IPPrefixesRemoteConfiguration,
) -> Self {
self.remote_configuration = Some(value);
self
}
pub fn synthetics(mut self, value: crate::datadogV1::model::IPPrefixesSynthetics) -> Self {
self.synthetics = Some(value);
self
}
pub fn synthetics_private_locations(
mut self,
value: crate::datadogV1::model::IPPrefixesSyntheticsPrivateLocations,
) -> Self {
self.synthetics_private_locations = Some(value);
self
}
pub fn version(mut self, value: i64) -> Self {
self.version = Some(value);
self
}
pub fn webhooks(mut self, value: crate::datadogV1::model::IPPrefixesWebhooks) -> Self {
self.webhooks = 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 IPRanges {
fn default() -> Self {
Self::new()
}
}
impl<'de> Deserialize<'de> for IPRanges {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct IPRangesVisitor;
impl<'a> Visitor<'a> for IPRangesVisitor {
type Value = IPRanges;
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 agents: Option<crate::datadogV1::model::IPPrefixesAgents> = None;
let mut api: Option<crate::datadogV1::model::IPPrefixesAPI> = None;
let mut apm: Option<crate::datadogV1::model::IPPrefixesAPM> = None;
let mut global: Option<crate::datadogV1::model::IPPrefixesGlobal> = None;
let mut logs: Option<crate::datadogV1::model::IPPrefixesLogs> = None;
let mut modified: Option<String> = None;
let mut orchestrator: Option<crate::datadogV1::model::IPPrefixesOrchestrator> =
None;
let mut process: Option<crate::datadogV1::model::IPPrefixesProcess> = None;
let mut remote_configuration: Option<
crate::datadogV1::model::IPPrefixesRemoteConfiguration,
> = None;
let mut synthetics: Option<crate::datadogV1::model::IPPrefixesSynthetics> = None;
let mut synthetics_private_locations: Option<
crate::datadogV1::model::IPPrefixesSyntheticsPrivateLocations,
> = None;
let mut version: Option<i64> = None;
let mut webhooks: Option<crate::datadogV1::model::IPPrefixesWebhooks> = 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() {
"agents" => {
if v.is_null() {
continue;
}
agents = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"api" => {
if v.is_null() {
continue;
}
api = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"apm" => {
if v.is_null() {
continue;
}
apm = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"global" => {
if v.is_null() {
continue;
}
global = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"logs" => {
if v.is_null() {
continue;
}
logs = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"modified" => {
if v.is_null() {
continue;
}
modified = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"orchestrator" => {
if v.is_null() {
continue;
}
orchestrator =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"process" => {
if v.is_null() {
continue;
}
process = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"remote-configuration" => {
if v.is_null() {
continue;
}
remote_configuration =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"synthetics" => {
if v.is_null() {
continue;
}
synthetics = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"synthetics-private-locations" => {
if v.is_null() {
continue;
}
synthetics_private_locations =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"version" => {
if v.is_null() {
continue;
}
version = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"webhooks" => {
if v.is_null() {
continue;
}
webhooks = 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 = IPRanges {
agents,
api,
apm,
global,
logs,
modified,
orchestrator,
process,
remote_configuration,
synthetics,
synthetics_private_locations,
version,
webhooks,
additional_properties,
_unparsed,
};
Ok(content)
}
}
deserializer.deserialize_any(IPRangesVisitor)
}
}