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 SharedDashboardInvitesDataObjectAttributes {
#[serde(rename = "created_at")]
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
#[serde(rename = "email")]
pub email: Option<String>,
#[serde(rename = "has_session")]
pub has_session: Option<bool>,
#[serde(rename = "invitation_expiry")]
pub invitation_expiry: Option<chrono::DateTime<chrono::Utc>>,
#[serde(
rename = "session_expiry",
default,
with = "::serde_with::rust::double_option"
)]
pub session_expiry: Option<Option<chrono::DateTime<chrono::Utc>>>,
#[serde(rename = "share_token")]
pub share_token: Option<String>,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}
impl SharedDashboardInvitesDataObjectAttributes {
pub fn new() -> SharedDashboardInvitesDataObjectAttributes {
SharedDashboardInvitesDataObjectAttributes {
created_at: None,
email: None,
has_session: None,
invitation_expiry: None,
session_expiry: None,
share_token: None,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}
pub fn created_at(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.created_at = Some(value);
self
}
pub fn email(mut self, value: String) -> Self {
self.email = Some(value);
self
}
pub fn has_session(mut self, value: bool) -> Self {
self.has_session = Some(value);
self
}
pub fn invitation_expiry(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.invitation_expiry = Some(value);
self
}
pub fn session_expiry(mut self, value: Option<chrono::DateTime<chrono::Utc>>) -> Self {
self.session_expiry = Some(value);
self
}
pub fn share_token(mut self, value: String) -> Self {
self.share_token = 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 SharedDashboardInvitesDataObjectAttributes {
fn default() -> Self {
Self::new()
}
}
impl<'de> Deserialize<'de> for SharedDashboardInvitesDataObjectAttributes {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct SharedDashboardInvitesDataObjectAttributesVisitor;
impl<'a> Visitor<'a> for SharedDashboardInvitesDataObjectAttributesVisitor {
type Value = SharedDashboardInvitesDataObjectAttributes;
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 created_at: Option<chrono::DateTime<chrono::Utc>> = None;
let mut email: Option<String> = None;
let mut has_session: Option<bool> = None;
let mut invitation_expiry: Option<chrono::DateTime<chrono::Utc>> = None;
let mut session_expiry: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
let mut share_token: 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() {
"created_at" => {
if v.is_null() {
continue;
}
created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"email" => {
if v.is_null() {
continue;
}
email = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"has_session" => {
if v.is_null() {
continue;
}
has_session =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"invitation_expiry" => {
if v.is_null() {
continue;
}
invitation_expiry =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"session_expiry" => {
session_expiry =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"share_token" => {
if v.is_null() {
continue;
}
share_token =
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 = SharedDashboardInvitesDataObjectAttributes {
created_at,
email,
has_session,
invitation_expiry,
session_expiry,
share_token,
additional_properties,
_unparsed,
};
Ok(content)
}
}
deserializer.deserialize_any(SharedDashboardInvitesDataObjectAttributesVisitor)
}
}