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 AppVersionAttributes {
#[serde(rename = "app_id")]
pub app_id: Option<uuid::Uuid>,
#[serde(rename = "created_at")]
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
#[serde(rename = "has_ever_been_published")]
pub has_ever_been_published: Option<bool>,
#[serde(rename = "name")]
pub name: Option<String>,
#[serde(rename = "updated_at")]
pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
#[serde(rename = "user_id")]
pub user_id: Option<i64>,
#[serde(rename = "user_name")]
pub user_name: Option<String>,
#[serde(rename = "user_uuid")]
pub user_uuid: Option<uuid::Uuid>,
#[serde(rename = "version")]
pub version: Option<i64>,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}
impl AppVersionAttributes {
pub fn new() -> AppVersionAttributes {
AppVersionAttributes {
app_id: None,
created_at: None,
has_ever_been_published: None,
name: None,
updated_at: None,
user_id: None,
user_name: None,
user_uuid: None,
version: None,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}
pub fn app_id(mut self, value: uuid::Uuid) -> Self {
self.app_id = Some(value);
self
}
pub fn created_at(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.created_at = Some(value);
self
}
pub fn has_ever_been_published(mut self, value: bool) -> Self {
self.has_ever_been_published = Some(value);
self
}
pub fn name(mut self, value: String) -> Self {
self.name = Some(value);
self
}
pub fn updated_at(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.updated_at = Some(value);
self
}
pub fn user_id(mut self, value: i64) -> Self {
self.user_id = Some(value);
self
}
pub fn user_name(mut self, value: String) -> Self {
self.user_name = Some(value);
self
}
pub fn user_uuid(mut self, value: uuid::Uuid) -> Self {
self.user_uuid = Some(value);
self
}
pub fn version(mut self, value: i64) -> Self {
self.version = 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 AppVersionAttributes {
fn default() -> Self {
Self::new()
}
}
impl<'de> Deserialize<'de> for AppVersionAttributes {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct AppVersionAttributesVisitor;
impl<'a> Visitor<'a> for AppVersionAttributesVisitor {
type Value = AppVersionAttributes;
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 app_id: Option<uuid::Uuid> = None;
let mut created_at: Option<chrono::DateTime<chrono::Utc>> = None;
let mut has_ever_been_published: Option<bool> = None;
let mut name: Option<String> = None;
let mut updated_at: Option<chrono::DateTime<chrono::Utc>> = None;
let mut user_id: Option<i64> = None;
let mut user_name: Option<String> = None;
let mut user_uuid: Option<uuid::Uuid> = None;
let mut version: Option<i64> = 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() {
"app_id" => {
if v.is_null() {
continue;
}
app_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"created_at" => {
if v.is_null() {
continue;
}
created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"has_ever_been_published" => {
if v.is_null() {
continue;
}
has_ever_been_published =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"name" => {
if v.is_null() {
continue;
}
name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"updated_at" => {
if v.is_null() {
continue;
}
updated_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"user_id" => {
if v.is_null() {
continue;
}
user_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"user_name" => {
if v.is_null() {
continue;
}
user_name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"user_uuid" => {
if v.is_null() {
continue;
}
user_uuid = 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)?);
}
&_ => {
if let Ok(value) = serde_json::from_value(v.clone()) {
additional_properties.insert(k, value);
}
}
}
}
let content = AppVersionAttributes {
app_id,
created_at,
has_ever_been_published,
name,
updated_at,
user_id,
user_name,
user_uuid,
version,
additional_properties,
_unparsed,
};
Ok(content)
}
}
deserializer.deserialize_any(AppVersionAttributesVisitor)
}
}