#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime, UriValue};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::social_showcase::ItemImage;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "social.showcase.library.item",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Item<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub category: Option<S>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub external_link: Option<UriValue<S>>,
pub images: Vec<ItemImage<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Data<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub notes: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_item_schema_version")]
pub schema_version: Option<i64>,
pub tags: Vec<S>,
pub title: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_at: Option<Datetime>,
pub visibility: ItemVisibility<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ItemVisibility<S: BosStr = DefaultStr> {
Public,
Unlisted,
Private,
Other(S),
}
impl<S: BosStr> ItemVisibility<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Public => "public",
Self::Unlisted => "unlisted",
Self::Private => "private",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"public" => Self::Public,
"unlisted" => Self::Unlisted,
"private" => Self::Private,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for ItemVisibility<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for ItemVisibility<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for ItemVisibility<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for ItemVisibility<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for ItemVisibility<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for ItemVisibility<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = ItemVisibility<S::Output>;
fn into_static(self) -> Self::Output {
match self {
ItemVisibility::Public => ItemVisibility::Public,
ItemVisibility::Unlisted => ItemVisibility::Unlisted,
ItemVisibility::Private => ItemVisibility::Private,
ItemVisibility::Other(v) => ItemVisibility::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ItemGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Item<S>,
}
impl<S: BosStr> Item<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, ItemRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ItemRecord;
impl XrpcResp for ItemRecord {
const NSID: &'static str = "social.showcase.library.item";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = ItemGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<ItemGetRecordOutput<S>> for Item<S> {
fn from(output: ItemGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Item<S> {
const NSID: &'static str = "social.showcase.library.item";
type Record = ItemRecord;
}
impl Collection for ItemRecord {
const NSID: &'static str = "social.showcase.library.item";
type Record = ItemRecord;
}
impl<S: BosStr> LexiconSchema for Item<S> {
fn nsid() -> &'static str {
"social.showcase.library.item"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_social_showcase_library_item()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.category {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("category"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 3000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 3000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.images;
#[allow(unused_comparisons)]
if value.len() > 6usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("images"),
max: 6usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.notes {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("notes"),
max: 2000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.tags;
#[allow(unused_comparisons)]
if value.len() > 20usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("tags"),
max: 20usize,
actual: value.len(),
});
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 300usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 300usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.visibility;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 10usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("visibility"),
max: 10usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
fn _default_item_schema_version() -> Option<i64> {
Some(1i64)
}
pub mod item_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Tags;
type Visibility;
type Images;
type CreatedAt;
type Title;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Tags = Unset;
type Visibility = Unset;
type Images = Unset;
type CreatedAt = Unset;
type Title = Unset;
}
pub struct SetTags<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTags<St> {}
impl<St: State> State for SetTags<St> {
type Tags = Set<members::tags>;
type Visibility = St::Visibility;
type Images = St::Images;
type CreatedAt = St::CreatedAt;
type Title = St::Title;
}
pub struct SetVisibility<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetVisibility<St> {}
impl<St: State> State for SetVisibility<St> {
type Tags = St::Tags;
type Visibility = Set<members::visibility>;
type Images = St::Images;
type CreatedAt = St::CreatedAt;
type Title = St::Title;
}
pub struct SetImages<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetImages<St> {}
impl<St: State> State for SetImages<St> {
type Tags = St::Tags;
type Visibility = St::Visibility;
type Images = Set<members::images>;
type CreatedAt = St::CreatedAt;
type Title = St::Title;
}
pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
impl<St: State> State for SetCreatedAt<St> {
type Tags = St::Tags;
type Visibility = St::Visibility;
type Images = St::Images;
type CreatedAt = Set<members::created_at>;
type Title = St::Title;
}
pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTitle<St> {}
impl<St: State> State for SetTitle<St> {
type Tags = St::Tags;
type Visibility = St::Visibility;
type Images = St::Images;
type CreatedAt = St::CreatedAt;
type Title = Set<members::title>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct tags(());
pub struct visibility(());
pub struct images(());
pub struct created_at(());
pub struct title(());
}
}
pub struct ItemBuilder<S: BosStr, St: item_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<Datetime>,
Option<S>,
Option<UriValue<S>>,
Option<Vec<ItemImage<S>>>,
Option<Data<S>>,
Option<S>,
Option<i64>,
Option<Vec<S>>,
Option<S>,
Option<Datetime>,
Option<ItemVisibility<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Item<S> {
pub fn new() -> ItemBuilder<S, item_state::Empty> {
ItemBuilder::new()
}
}
impl<S: BosStr> ItemBuilder<S, item_state::Empty> {
pub fn new() -> Self {
ItemBuilder {
_state: PhantomData,
_fields: (
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: item_state::State> ItemBuilder<S, St> {
pub fn category(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_category(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> ItemBuilder<S, St>
where
St: item_state::State,
St::CreatedAt: item_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> ItemBuilder<S, item_state::SetCreatedAt<St>> {
self._fields.1 = Option::Some(value.into());
ItemBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: item_state::State> ItemBuilder<S, St> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: item_state::State> ItemBuilder<S, St> {
pub fn external_link(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_external_link(mut self, value: Option<UriValue<S>>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> ItemBuilder<S, St>
where
St: item_state::State,
St::Images: item_state::IsUnset,
{
pub fn images(
mut self,
value: impl Into<Vec<ItemImage<S>>>,
) -> ItemBuilder<S, item_state::SetImages<St>> {
self._fields.4 = Option::Some(value.into());
ItemBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: item_state::State> ItemBuilder<S, St> {
pub fn metadata(mut self, value: impl Into<Option<Data<S>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_metadata(mut self, value: Option<Data<S>>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St: item_state::State> ItemBuilder<S, St> {
pub fn notes(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_notes(mut self, value: Option<S>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St: item_state::State> ItemBuilder<S, St> {
pub fn schema_version(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_schema_version(mut self, value: Option<i64>) -> Self {
self._fields.7 = value;
self
}
}
impl<S: BosStr, St> ItemBuilder<S, St>
where
St: item_state::State,
St::Tags: item_state::IsUnset,
{
pub fn tags(
mut self,
value: impl Into<Vec<S>>,
) -> ItemBuilder<S, item_state::SetTags<St>> {
self._fields.8 = Option::Some(value.into());
ItemBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ItemBuilder<S, St>
where
St: item_state::State,
St::Title: item_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> ItemBuilder<S, item_state::SetTitle<St>> {
self._fields.9 = Option::Some(value.into());
ItemBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: item_state::State> ItemBuilder<S, St> {
pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.10 = value.into();
self
}
pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
self._fields.10 = value;
self
}
}
impl<S: BosStr, St> ItemBuilder<S, St>
where
St: item_state::State,
St::Visibility: item_state::IsUnset,
{
pub fn visibility(
mut self,
value: impl Into<ItemVisibility<S>>,
) -> ItemBuilder<S, item_state::SetVisibility<St>> {
self._fields.11 = Option::Some(value.into());
ItemBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ItemBuilder<S, St>
where
St: item_state::State,
St::Tags: item_state::IsSet,
St::Visibility: item_state::IsSet,
St::Images: item_state::IsSet,
St::CreatedAt: item_state::IsSet,
St::Title: item_state::IsSet,
{
pub fn build(self) -> Item<S> {
Item {
category: self._fields.0,
created_at: self._fields.1.unwrap(),
description: self._fields.2,
external_link: self._fields.3,
images: self._fields.4.unwrap(),
metadata: self._fields.5,
notes: self._fields.6,
schema_version: self._fields.7.or_else(|| Some(1i64)),
tags: self._fields.8.unwrap(),
title: self._fields.9.unwrap(),
updated_at: self._fields.10,
visibility: self._fields.11.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Item<S> {
Item {
category: self._fields.0,
created_at: self._fields.1.unwrap(),
description: self._fields.2,
external_link: self._fields.3,
images: self._fields.4.unwrap(),
metadata: self._fields.5,
notes: self._fields.6,
schema_version: self._fields.7.or_else(|| Some(1i64)),
tags: self._fields.8.unwrap(),
title: self._fields.9.unwrap(),
updated_at: self._fields.10,
visibility: self._fields.11.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_social_showcase_library_item() -> LexiconDoc<'static> {
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
use alloc::collections::BTreeMap;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("social.showcase.library.item"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(CowStr::new_static("Showcase item record")),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("title"), SmolStr::new_static("tags"),
SmolStr::new_static("images"),
SmolStr::new_static("visibility"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("category"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Category/type of item"),
),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Item description")),
max_length: Some(3000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("externalLink"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Link to external site"),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("images"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Embedded image blobs (max 6 images, 2000x2000px max, 5MB each)",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("social.showcase.defs#itemImage"),
..Default::default()
}),
max_length: Some(6usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("metadata"),
LexObjectProperty::Unknown(LexUnknown {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("notes"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Personal notes or story about the item"),
),
max_length: Some(2000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("schemaVersion"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("tags"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static("Tags for discovery (max 20)"),
),
items: LexArrayItem::String(LexString {
max_length: Some(64usize),
..Default::default()
}),
max_length: Some(20usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Item title")),
max_length: Some(300usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("updatedAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("visibility"),
LexObjectProperty::String(LexString {
max_length: Some(10usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}