#[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};
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};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "org.stormlightlabs.malfestio.deck",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Deck<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub card_refs: Option<Vec<AtUri<S>>>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub language: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub license: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source_refs: Option<Vec<AtUri<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<S>>,
pub title: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_at: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub visibility: Option<DeckVisibility<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 DeckVisibility<S: BosStr = DefaultStr> {
Private,
Unlisted,
Public,
Other(S),
}
impl<S: BosStr> DeckVisibility<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Private => "private",
Self::Unlisted => "unlisted",
Self::Public => "public",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"private" => Self::Private,
"unlisted" => Self::Unlisted,
"public" => Self::Public,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for DeckVisibility<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for DeckVisibility<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for DeckVisibility<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 DeckVisibility<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 DeckVisibility<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for DeckVisibility<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = DeckVisibility<S::Output>;
fn into_static(self) -> Self::Output {
match self {
DeckVisibility::Private => DeckVisibility::Private,
DeckVisibility::Unlisted => DeckVisibility::Unlisted,
DeckVisibility::Public => DeckVisibility::Public,
DeckVisibility::Other(v) => DeckVisibility::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct DeckGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Deck<S>,
}
impl<S: BosStr> Deck<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, DeckRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DeckRecord;
impl XrpcResp for DeckRecord {
const NSID: &'static str = "org.stormlightlabs.malfestio.deck";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = DeckGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<DeckGetRecordOutput<S>> for Deck<S> {
fn from(output: DeckGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Deck<S> {
const NSID: &'static str = "org.stormlightlabs.malfestio.deck";
type Record = DeckRecord;
}
impl Collection for DeckRecord {
const NSID: &'static str = "org.stormlightlabs.malfestio.deck";
type Record = DeckRecord;
}
impl<S: BosStr> LexiconSchema for Deck<S> {
fn nsid() -> &'static str {
"org.stormlightlabs.malfestio.deck"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_stormlightlabs_malfestio_deck()
}
fn validate(&self) -> Result<(), ConstraintError> {
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()),
});
}
}
if let Some(ref value) = self.language {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 20usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("language"),
max: 20usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.license {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 500usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("license"),
max: 500usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.tags {
#[allow(unused_comparisons)]
if value.len() > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("tags"),
max: 64usize,
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()),
});
}
}
if let Some(ref value) = self.visibility {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("visibility"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod deck_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 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 DeckBuilder<S: BosStr, St: deck_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Vec<AtUri<S>>>,
Option<Datetime>,
Option<S>,
Option<S>,
Option<S>,
Option<Vec<AtUri<S>>>,
Option<Vec<S>>,
Option<S>,
Option<Datetime>,
Option<DeckVisibility<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Deck<S> {
pub fn new() -> DeckBuilder<S, deck_state::Empty> {
DeckBuilder::new()
}
}
impl<S: BosStr> DeckBuilder<S, deck_state::Empty> {
pub fn new() -> Self {
DeckBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: deck_state::State> DeckBuilder<S, St> {
pub fn card_refs(mut self, value: impl Into<Option<Vec<AtUri<S>>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_card_refs(mut self, value: Option<Vec<AtUri<S>>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> DeckBuilder<S, St>
where
St: deck_state::State,
St::CreatedAt: deck_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> DeckBuilder<S, deck_state::SetCreatedAt<St>> {
self._fields.1 = Option::Some(value.into());
DeckBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: deck_state::State> DeckBuilder<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: deck_state::State> DeckBuilder<S, St> {
pub fn language(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_language(mut self, value: Option<S>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St: deck_state::State> DeckBuilder<S, St> {
pub fn license(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_license(mut self, value: Option<S>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St: deck_state::State> DeckBuilder<S, St> {
pub fn source_refs(mut self, value: impl Into<Option<Vec<AtUri<S>>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_source_refs(mut self, value: Option<Vec<AtUri<S>>>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St: deck_state::State> DeckBuilder<S, St> {
pub fn tags(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_tags(mut self, value: Option<Vec<S>>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St> DeckBuilder<S, St>
where
St: deck_state::State,
St::Title: deck_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> DeckBuilder<S, deck_state::SetTitle<St>> {
self._fields.7 = Option::Some(value.into());
DeckBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: deck_state::State> DeckBuilder<S, St> {
pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
self._fields.8 = value;
self
}
}
impl<S: BosStr, St: deck_state::State> DeckBuilder<S, St> {
pub fn visibility(mut self, value: impl Into<Option<DeckVisibility<S>>>) -> Self {
self._fields.9 = value.into();
self
}
pub fn maybe_visibility(mut self, value: Option<DeckVisibility<S>>) -> Self {
self._fields.9 = value;
self
}
}
impl<S: BosStr, St> DeckBuilder<S, St>
where
St: deck_state::State,
St::Title: deck_state::IsSet,
St::CreatedAt: deck_state::IsSet,
{
pub fn build(self) -> Deck<S> {
Deck {
card_refs: self._fields.0,
created_at: self._fields.1.unwrap(),
description: self._fields.2,
language: self._fields.3,
license: self._fields.4,
source_refs: self._fields.5,
tags: self._fields.6,
title: self._fields.7.unwrap(),
updated_at: self._fields.8,
visibility: self._fields.9,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Deck<S> {
Deck {
card_refs: self._fields.0,
created_at: self._fields.1.unwrap(),
description: self._fields.2,
language: self._fields.3,
license: self._fields.4,
source_refs: self._fields.5,
tags: self._fields.6,
title: self._fields.7.unwrap(),
updated_at: self._fields.8,
visibility: self._fields.9,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_org_stormlightlabs_malfestio_deck() -> 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("org.stormlightlabs.malfestio.deck"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static("A collection of flashcards and sources."),
),
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("cardRefs"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Ordered list of references to cards in this deck.",
),
),
items: LexArrayItem::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
..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("Description of the deck context."),
),
max_length: Some(3000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("language"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Language code for the deck content (e.g., 'en', 'es', 'fr').",
),
),
max_length: Some(20usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("license"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("License for the deck content."),
),
max_length: Some(500usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("sourceRefs"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"References to source materials (articles, lectures) used in this deck.",
),
),
items: LexArrayItem::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("tags"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::String(LexString {
max_length: Some(100usize),
..Default::default()
}),
max_length: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Title of the deck.")),
max_length: Some(300usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("updatedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Timestamp of last update."),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("visibility"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Visibility setting for the deck."),
),
max_length: Some(100usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}