pub mod item;
#[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::{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};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::com_atproto::label::Label;
use crate::com_atproto::label::SelfLabels;
use crate::social_grain::actor::ProfileView;
use crate::social_grain::photo::PhotoView;
#[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",
rename = "social.grain.gallery",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Gallery<S: BosStr = DefaultStr> {
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub labels: Option<SelfLabels<S>>,
pub title: 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")]
pub struct GalleryGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Gallery<S>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct GalleryView<S: BosStr = DefaultStr> {
pub cid: Cid<S>,
pub creator: ProfileView<S>,
pub indexed_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub items: Option<Vec<PhotoView<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub labels: Option<Vec<Label<S>>>,
pub record: Data<S>,
pub uri: AtUri<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> Gallery<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, GalleryRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GalleryRecord;
impl XrpcResp for GalleryRecord {
const NSID: &'static str = "social.grain.gallery";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = GalleryGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<GalleryGetRecordOutput<S>> for Gallery<S> {
fn from(output: GalleryGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Gallery<S> {
const NSID: &'static str = "social.grain.gallery";
type Record = GalleryRecord;
}
impl Collection for GalleryRecord {
const NSID: &'static str = "social.grain.gallery";
type Record = GalleryRecord;
}
impl<S: BosStr> LexiconSchema for Gallery<S> {
fn nsid() -> &'static str {
"social.grain.gallery"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_social_grain_gallery()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 1000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 1000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for GalleryView<S> {
fn nsid() -> &'static str {
"social.grain.gallery.defs"
}
fn def_name() -> &'static str {
"galleryView"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_social_grain_gallery_defs()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod gallery_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 GalleryBuilder<S: BosStr, St: gallery_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Datetime>,
Option<S>,
Option<SelfLabels<S>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Gallery<S> {
pub fn new() -> GalleryBuilder<S, gallery_state::Empty> {
GalleryBuilder::new()
}
}
impl<S: BosStr> GalleryBuilder<S, gallery_state::Empty> {
pub fn new() -> Self {
GalleryBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> GalleryBuilder<S, St>
where
St: gallery_state::State,
St::CreatedAt: gallery_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> GalleryBuilder<S, gallery_state::SetCreatedAt<St>> {
self._fields.0 = Option::Some(value.into());
GalleryBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: gallery_state::State> GalleryBuilder<S, St> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: gallery_state::State> GalleryBuilder<S, St> {
pub fn labels(mut self, value: impl Into<Option<SelfLabels<S>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_labels(mut self, value: Option<SelfLabels<S>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St> GalleryBuilder<S, St>
where
St: gallery_state::State,
St::Title: gallery_state::IsUnset,
{
pub fn title(mut self, value: impl Into<S>) -> GalleryBuilder<S, gallery_state::SetTitle<St>> {
self._fields.3 = Option::Some(value.into());
GalleryBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> GalleryBuilder<S, St>
where
St: gallery_state::State,
St::Title: gallery_state::IsSet,
St::CreatedAt: gallery_state::IsSet,
{
pub fn build(self) -> Gallery<S> {
Gallery {
created_at: self._fields.0.unwrap(),
description: self._fields.1,
labels: self._fields.2,
title: self._fields.3.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Gallery<S> {
Gallery {
created_at: self._fields.0.unwrap(),
description: self._fields.1,
labels: self._fields.2,
title: self._fields.3.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_social_grain_gallery() -> 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("social.grain.gallery"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
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("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
max_length: Some(1000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("labels"),
LexObjectProperty::Union(LexRefUnion {
description: Some(
CowStr::new_static(
"Self-label values for this post. Effectively content warnings.",
),
),
refs: vec![
CowStr::new_static("com.atproto.label.defs#selfLabels")
],
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
max_length: Some(100usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod gallery_view_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 Record;
type Creator;
type IndexedAt;
type Uri;
type Cid;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Record = Unset;
type Creator = Unset;
type IndexedAt = Unset;
type Uri = Unset;
type Cid = Unset;
}
pub struct SetRecord<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetRecord<St> {}
impl<St: State> State for SetRecord<St> {
type Record = Set<members::record>;
type Creator = St::Creator;
type IndexedAt = St::IndexedAt;
type Uri = St::Uri;
type Cid = St::Cid;
}
pub struct SetCreator<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreator<St> {}
impl<St: State> State for SetCreator<St> {
type Record = St::Record;
type Creator = Set<members::creator>;
type IndexedAt = St::IndexedAt;
type Uri = St::Uri;
type Cid = St::Cid;
}
pub struct SetIndexedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetIndexedAt<St> {}
impl<St: State> State for SetIndexedAt<St> {
type Record = St::Record;
type Creator = St::Creator;
type IndexedAt = Set<members::indexed_at>;
type Uri = St::Uri;
type Cid = St::Cid;
}
pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUri<St> {}
impl<St: State> State for SetUri<St> {
type Record = St::Record;
type Creator = St::Creator;
type IndexedAt = St::IndexedAt;
type Uri = Set<members::uri>;
type Cid = St::Cid;
}
pub struct SetCid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCid<St> {}
impl<St: State> State for SetCid<St> {
type Record = St::Record;
type Creator = St::Creator;
type IndexedAt = St::IndexedAt;
type Uri = St::Uri;
type Cid = Set<members::cid>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct record(());
pub struct creator(());
pub struct indexed_at(());
pub struct uri(());
pub struct cid(());
}
}
pub struct GalleryViewBuilder<S: BosStr, St: gallery_view_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Cid<S>>,
Option<ProfileView<S>>,
Option<Datetime>,
Option<Vec<PhotoView<S>>>,
Option<Vec<Label<S>>>,
Option<Data<S>>,
Option<AtUri<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> GalleryView<S> {
pub fn new() -> GalleryViewBuilder<S, gallery_view_state::Empty> {
GalleryViewBuilder::new()
}
}
impl<S: BosStr> GalleryViewBuilder<S, gallery_view_state::Empty> {
pub fn new() -> Self {
GalleryViewBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> GalleryViewBuilder<S, St>
where
St: gallery_view_state::State,
St::Cid: gallery_view_state::IsUnset,
{
pub fn cid(
mut self,
value: impl Into<Cid<S>>,
) -> GalleryViewBuilder<S, gallery_view_state::SetCid<St>> {
self._fields.0 = Option::Some(value.into());
GalleryViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> GalleryViewBuilder<S, St>
where
St: gallery_view_state::State,
St::Creator: gallery_view_state::IsUnset,
{
pub fn creator(
mut self,
value: impl Into<ProfileView<S>>,
) -> GalleryViewBuilder<S, gallery_view_state::SetCreator<St>> {
self._fields.1 = Option::Some(value.into());
GalleryViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> GalleryViewBuilder<S, St>
where
St: gallery_view_state::State,
St::IndexedAt: gallery_view_state::IsUnset,
{
pub fn indexed_at(
mut self,
value: impl Into<Datetime>,
) -> GalleryViewBuilder<S, gallery_view_state::SetIndexedAt<St>> {
self._fields.2 = Option::Some(value.into());
GalleryViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: gallery_view_state::State> GalleryViewBuilder<S, St> {
pub fn items(mut self, value: impl Into<Option<Vec<PhotoView<S>>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_items(mut self, value: Option<Vec<PhotoView<S>>>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St: gallery_view_state::State> GalleryViewBuilder<S, St> {
pub fn labels(mut self, value: impl Into<Option<Vec<Label<S>>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_labels(mut self, value: Option<Vec<Label<S>>>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St> GalleryViewBuilder<S, St>
where
St: gallery_view_state::State,
St::Record: gallery_view_state::IsUnset,
{
pub fn record(
mut self,
value: impl Into<Data<S>>,
) -> GalleryViewBuilder<S, gallery_view_state::SetRecord<St>> {
self._fields.5 = Option::Some(value.into());
GalleryViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> GalleryViewBuilder<S, St>
where
St: gallery_view_state::State,
St::Uri: gallery_view_state::IsUnset,
{
pub fn uri(
mut self,
value: impl Into<AtUri<S>>,
) -> GalleryViewBuilder<S, gallery_view_state::SetUri<St>> {
self._fields.6 = Option::Some(value.into());
GalleryViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> GalleryViewBuilder<S, St>
where
St: gallery_view_state::State,
St::Record: gallery_view_state::IsSet,
St::Creator: gallery_view_state::IsSet,
St::IndexedAt: gallery_view_state::IsSet,
St::Uri: gallery_view_state::IsSet,
St::Cid: gallery_view_state::IsSet,
{
pub fn build(self) -> GalleryView<S> {
GalleryView {
cid: self._fields.0.unwrap(),
creator: self._fields.1.unwrap(),
indexed_at: self._fields.2.unwrap(),
items: self._fields.3,
labels: self._fields.4,
record: self._fields.5.unwrap(),
uri: self._fields.6.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> GalleryView<S> {
GalleryView {
cid: self._fields.0.unwrap(),
creator: self._fields.1.unwrap(),
indexed_at: self._fields.2.unwrap(),
items: self._fields.3,
labels: self._fields.4,
record: self._fields.5.unwrap(),
uri: self._fields.6.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_social_grain_gallery_defs() -> 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("social.grain.gallery.defs"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("galleryView"),
LexUserType::Object(LexObject {
required: Some(vec![
SmolStr::new_static("uri"),
SmolStr::new_static("cid"),
SmolStr::new_static("creator"),
SmolStr::new_static("record"),
SmolStr::new_static("indexedAt"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("cid"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Cid),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("creator"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("social.grain.actor.defs#profileView"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("indexedAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("items"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Union(LexRefUnion {
refs: vec![CowStr::new_static(
"social.grain.photo.defs#photoView",
)],
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("labels"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.label.defs#label"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("record"),
LexObjectProperty::Unknown(LexUnknown {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("uri"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}