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 DdsqlTabularQueryResponseAttributes {
#[serde(rename = "columns")]
pub columns: Option<Vec<crate::datadogV2::model::DdsqlTabularQueryColumn>>,
#[serde(rename = "query_id")]
pub query_id: Option<String>,
#[serde(rename = "state")]
pub state: crate::datadogV2::model::DdsqlTabularQueryState,
#[serde(rename = "warnings")]
pub warnings: Option<Vec<String>>,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}
impl DdsqlTabularQueryResponseAttributes {
pub fn new(
state: crate::datadogV2::model::DdsqlTabularQueryState,
) -> DdsqlTabularQueryResponseAttributes {
DdsqlTabularQueryResponseAttributes {
columns: None,
query_id: None,
state,
warnings: None,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}
pub fn columns(mut self, value: Vec<crate::datadogV2::model::DdsqlTabularQueryColumn>) -> Self {
self.columns = Some(value);
self
}
pub fn query_id(mut self, value: String) -> Self {
self.query_id = Some(value);
self
}
pub fn warnings(mut self, value: Vec<String>) -> Self {
self.warnings = 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 DdsqlTabularQueryResponseAttributes {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct DdsqlTabularQueryResponseAttributesVisitor;
impl<'a> Visitor<'a> for DdsqlTabularQueryResponseAttributesVisitor {
type Value = DdsqlTabularQueryResponseAttributes;
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 columns: Option<Vec<crate::datadogV2::model::DdsqlTabularQueryColumn>> =
None;
let mut query_id: Option<String> = None;
let mut state: Option<crate::datadogV2::model::DdsqlTabularQueryState> = None;
let mut warnings: Option<Vec<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() {
"columns" => {
if v.is_null() {
continue;
}
columns = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"query_id" => {
if v.is_null() {
continue;
}
query_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"state" => {
state = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
if let Some(ref _state) = state {
match _state {
crate::datadogV2::model::DdsqlTabularQueryState::UnparsedObject(_state) => {
_unparsed = true;
},
_ => {}
}
}
}
"warnings" => {
if v.is_null() {
continue;
}
warnings = 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 state = state.ok_or_else(|| M::Error::missing_field("state"))?;
let content = DdsqlTabularQueryResponseAttributes {
columns,
query_id,
state,
warnings,
additional_properties,
_unparsed,
};
Ok(content)
}
}
deserializer.deserialize_any(DdsqlTabularQueryResponseAttributesVisitor)
}
}