#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, 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::RecordError;
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::com_atproto::repo::strong_ref::StrongRef;
use crate::org_hypercerts::LargeImage;
use crate::org_hypercerts::SmallImage;
use crate::org_hypercerts::Uri;
use crate::org_hypercerts::collection;
use crate::pub_leaflet::pages::linear_document::LinearDocument;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Item<S: BosStr = DefaultStr> {
pub item_identifier: StrongRef<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub item_weight: Option<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "org.hypercerts.collection",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Collection<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub avatar: Option<CollectionAvatar<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub banner: Option<CollectionBanner<S>>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<LinearDocument<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub items: Option<Vec<collection::Item<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub location: Option<StrongRef<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub short_description: Option<S>,
pub title: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#type: Option<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum CollectionAvatar<S: BosStr = DefaultStr> {
#[serde(rename = "org.hypercerts.defs#uri")]
Uri(Box<Uri<S>>),
#[serde(rename = "org.hypercerts.defs#smallImage")]
SmallImage(Box<SmallImage<S>>),
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum CollectionBanner<S: BosStr = DefaultStr> {
#[serde(rename = "org.hypercerts.defs#uri")]
Uri(Box<Uri<S>>),
#[serde(rename = "org.hypercerts.defs#largeImage")]
LargeImage(Box<LargeImage<S>>),
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CollectionGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Collection<S>,
}
impl<S: BosStr> Collection<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, CollectionRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
impl<S: BosStr> LexiconSchema for Item<S> {
fn nsid() -> &'static str {
"org.hypercerts.collection"
}
fn def_name() -> &'static str {
"item"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_hypercerts_collection()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.item_weight {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("item_weight"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CollectionRecord;
impl XrpcResp for CollectionRecord {
const NSID: &'static str = "org.hypercerts.collection";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = CollectionGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<CollectionGetRecordOutput<S>> for Collection<S> {
fn from(output: CollectionGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> jacquard_common::types::collection::Collection for Collection<S> {
const NSID: &'static str = "org.hypercerts.collection";
type Record = CollectionRecord;
}
impl jacquard_common::types::collection::Collection for CollectionRecord {
const NSID: &'static str = "org.hypercerts.collection";
type Record = CollectionRecord;
}
impl<S: BosStr> LexiconSchema for Collection<S> {
fn nsid() -> &'static str {
"org.hypercerts.collection"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_hypercerts_collection()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.items {
#[allow(unused_comparisons)]
if value.len() > 1000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("items"),
max: 1000usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.short_description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 3000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("short_description"),
max: 3000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.short_description {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 300usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("short_description"),
max: 300usize,
actual: count,
});
}
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 800usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 800usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.title;
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 80usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("title"),
max: 80usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.r#type {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("type"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod item_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type ItemIdentifier;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type ItemIdentifier = Unset;
}
pub struct SetItemIdentifier<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetItemIdentifier<St> {}
impl<St: State> State for SetItemIdentifier<St> {
type ItemIdentifier = Set<members::item_identifier>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct item_identifier(());
}
}
pub struct ItemBuilder<S: BosStr, St: item_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<StrongRef<S>>, Option<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),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ItemBuilder<S, St>
where
St: item_state::State,
St::ItemIdentifier: item_state::IsUnset,
{
pub fn item_identifier(
mut self,
value: impl Into<StrongRef<S>>,
) -> ItemBuilder<S, item_state::SetItemIdentifier<St>> {
self._fields.0 = Option::Some(value.into());
ItemBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: item_state::State> ItemBuilder<S, St> {
pub fn item_weight(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_item_weight(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> ItemBuilder<S, St>
where
St: item_state::State,
St::ItemIdentifier: item_state::IsSet,
{
pub fn build(self) -> Item<S> {
Item {
item_identifier: self._fields.0.unwrap(),
item_weight: self._fields.1,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Item<S> {
Item {
item_identifier: self._fields.0.unwrap(),
item_weight: self._fields.1,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_org_hypercerts_collection() -> LexiconDoc<'static> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("org.hypercerts.collection"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("item"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("itemIdentifier")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("itemIdentifier"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("itemWeight"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Optional weight for this item (positive numeric value stored as string). Weights do not need to sum to a specific total; normalization can be performed by the consuming application as needed.",
),
),
max_length: Some(100usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A collection/group of items (activities and/or other collections). Collections support recursive nesting.",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("title"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("avatar"),
LexObjectProperty::Union(LexRefUnion {
description: Some(
CowStr::new_static(
"The collection's avatar/profile image as a URI or image blob.",
),
),
refs: vec![
CowStr::new_static("org.hypercerts.defs#uri"),
CowStr::new_static("org.hypercerts.defs#smallImage")
],
..Default::default()
}),
);
map.insert(
SmolStr::new_static("banner"),
LexObjectProperty::Union(LexRefUnion {
description: Some(
CowStr::new_static(
"Larger horizontal image to display behind the collection view.",
),
),
refs: vec![
CowStr::new_static("org.hypercerts.defs#uri"),
CowStr::new_static("org.hypercerts.defs#largeImage")
],
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Client-declared timestamp when this record was originally created",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static(
"pub.leaflet.pages.linearDocument#main",
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("items"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Array of items in this collection with optional weights.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#item"),
..Default::default()
}),
max_length: Some(1000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("location"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("shortDescription"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Short summary of this collection, suitable for previews and list views",
),
),
max_length: Some(3000usize),
max_graphemes: Some(300usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Display name for this collection (e.g. 'Q1 2025 Impact Projects')",
),
),
max_length: Some(800usize),
max_graphemes: Some(80usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("type"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The type of this collection. Possible fields can be 'favorites', 'project', or any other type of collection.",
),
),
max_length: Some(64usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod collection_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Title;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Title = Unset;
type CreatedAt = Unset;
}
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 Title = Set<members::title>;
type CreatedAt = St::CreatedAt;
}
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 Title = St::Title;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct title(());
pub struct created_at(());
}
}
pub struct CollectionBuilder<S: BosStr, St: collection_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<CollectionAvatar<S>>,
Option<CollectionBanner<S>>,
Option<Datetime>,
Option<LinearDocument<S>>,
Option<Vec<collection::Item<S>>>,
Option<StrongRef<S>>,
Option<S>,
Option<S>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Collection<S> {
pub fn new() -> CollectionBuilder<S, collection_state::Empty> {
CollectionBuilder::new()
}
}
impl<S: BosStr> CollectionBuilder<S, collection_state::Empty> {
pub fn new() -> Self {
CollectionBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: collection_state::State> CollectionBuilder<S, St> {
pub fn avatar(mut self, value: impl Into<Option<CollectionAvatar<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_avatar(mut self, value: Option<CollectionAvatar<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: collection_state::State> CollectionBuilder<S, St> {
pub fn banner(mut self, value: impl Into<Option<CollectionBanner<S>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_banner(mut self, value: Option<CollectionBanner<S>>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> CollectionBuilder<S, St>
where
St: collection_state::State,
St::CreatedAt: collection_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> CollectionBuilder<S, collection_state::SetCreatedAt<St>> {
self._fields.2 = Option::Some(value.into());
CollectionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: collection_state::State> CollectionBuilder<S, St> {
pub fn description(mut self, value: impl Into<Option<LinearDocument<S>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<LinearDocument<S>>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St: collection_state::State> CollectionBuilder<S, St> {
pub fn items(mut self, value: impl Into<Option<Vec<collection::Item<S>>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_items(mut self, value: Option<Vec<collection::Item<S>>>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St: collection_state::State> CollectionBuilder<S, St> {
pub fn location(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_location(mut self, value: Option<StrongRef<S>>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St: collection_state::State> CollectionBuilder<S, St> {
pub fn short_description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_short_description(mut self, value: Option<S>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St> CollectionBuilder<S, St>
where
St: collection_state::State,
St::Title: collection_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> CollectionBuilder<S, collection_state::SetTitle<St>> {
self._fields.7 = Option::Some(value.into());
CollectionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: collection_state::State> CollectionBuilder<S, St> {
pub fn r#type(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_type(mut self, value: Option<S>) -> Self {
self._fields.8 = value;
self
}
}
impl<S: BosStr, St> CollectionBuilder<S, St>
where
St: collection_state::State,
St::Title: collection_state::IsSet,
St::CreatedAt: collection_state::IsSet,
{
pub fn build(self) -> Collection<S> {
Collection {
avatar: self._fields.0,
banner: self._fields.1,
created_at: self._fields.2.unwrap(),
description: self._fields.3,
items: self._fields.4,
location: self._fields.5,
short_description: self._fields.6,
title: self._fields.7.unwrap(),
r#type: self._fields.8,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Collection<S> {
Collection {
avatar: self._fields.0,
banner: self._fields.1,
created_at: self._fields.2.unwrap(),
description: self._fields.3,
items: self._fields.4,
location: self._fields.5,
short_description: self._fields.6,
title: self._fields.7.unwrap(),
r#type: self._fields.8,
extra_data: Some(extra_data),
}
}
}