#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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::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::com_atproto::repo::strong_ref::StrongRef;
use crate::sh_weaver::actor::Author;
use crate::sh_weaver::notebook::ContentRating;
use crate::sh_weaver::notebook::ContentWarnings;
use crate::sh_weaver::notebook::Tags;
use crate::sh_weaver::notebook::Title;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", rename = "sh.weaver.notebook.chapter", tag = "$type")]
pub struct Chapter<'a> {
#[serde(borrow)]
pub authors: Vec<Author<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub content_warnings: Option<ContentWarnings<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub created_at: Option<Datetime>,
#[serde(borrow)]
pub entry_list: Vec<StrongRef<'a>>,
#[serde(borrow)]
pub notebook: StrongRef<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub rating: Option<ContentRating<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub tags: Option<Tags<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub title: Option<Title<'a>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ChapterGetRecordOutput<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cid: Option<Cid<'a>>,
#[serde(borrow)]
pub uri: AtUri<'a>,
#[serde(borrow)]
pub value: Chapter<'a>,
}
impl<'a> Chapter<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, ChapterRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ChapterRecord;
impl XrpcResp for ChapterRecord {
const NSID: &'static str = "sh.weaver.notebook.chapter";
const ENCODING: &'static str = "application/json";
type Output<'de> = ChapterGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<ChapterGetRecordOutput<'_>> for Chapter<'_> {
fn from(output: ChapterGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Chapter<'_> {
const NSID: &'static str = "sh.weaver.notebook.chapter";
type Record = ChapterRecord;
}
impl Collection for ChapterRecord {
const NSID: &'static str = "sh.weaver.notebook.chapter";
type Record = ChapterRecord;
}
impl<'a> LexiconSchema for Chapter<'a> {
fn nsid() -> &'static str {
"sh.weaver.notebook.chapter"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_weaver_notebook_chapter()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod chapter_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 Authors;
type Notebook;
type EntryList;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Authors = Unset;
type Notebook = Unset;
type EntryList = Unset;
}
pub struct SetAuthors<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetAuthors<S> {}
impl<S: State> State for SetAuthors<S> {
type Authors = Set<members::authors>;
type Notebook = S::Notebook;
type EntryList = S::EntryList;
}
pub struct SetNotebook<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetNotebook<S> {}
impl<S: State> State for SetNotebook<S> {
type Authors = S::Authors;
type Notebook = Set<members::notebook>;
type EntryList = S::EntryList;
}
pub struct SetEntryList<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetEntryList<S> {}
impl<S: State> State for SetEntryList<S> {
type Authors = S::Authors;
type Notebook = S::Notebook;
type EntryList = Set<members::entry_list>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct authors(());
pub struct notebook(());
pub struct entry_list(());
}
}
pub struct ChapterBuilder<'a, S: chapter_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Vec<Author<'a>>>,
Option<ContentWarnings<'a>>,
Option<Datetime>,
Option<Vec<StrongRef<'a>>>,
Option<StrongRef<'a>>,
Option<ContentRating<'a>>,
Option<Tags<'a>>,
Option<Title<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Chapter<'a> {
pub fn new() -> ChapterBuilder<'a, chapter_state::Empty> {
ChapterBuilder::new()
}
}
impl<'a> ChapterBuilder<'a, chapter_state::Empty> {
pub fn new() -> Self {
ChapterBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> ChapterBuilder<'a, S>
where
S: chapter_state::State,
S::Authors: chapter_state::IsUnset,
{
pub fn authors(
mut self,
value: impl Into<Vec<Author<'a>>>,
) -> ChapterBuilder<'a, chapter_state::SetAuthors<S>> {
self._fields.0 = Option::Some(value.into());
ChapterBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: chapter_state::State> ChapterBuilder<'a, S> {
pub fn content_warnings(
mut self,
value: impl Into<Option<ContentWarnings<'a>>>,
) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_content_warnings(mut self, value: Option<ContentWarnings<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S: chapter_state::State> ChapterBuilder<'a, S> {
pub fn created_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_created_at(mut self, value: Option<Datetime>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S> ChapterBuilder<'a, S>
where
S: chapter_state::State,
S::EntryList: chapter_state::IsUnset,
{
pub fn entry_list(
mut self,
value: impl Into<Vec<StrongRef<'a>>>,
) -> ChapterBuilder<'a, chapter_state::SetEntryList<S>> {
self._fields.3 = Option::Some(value.into());
ChapterBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ChapterBuilder<'a, S>
where
S: chapter_state::State,
S::Notebook: chapter_state::IsUnset,
{
pub fn notebook(
mut self,
value: impl Into<StrongRef<'a>>,
) -> ChapterBuilder<'a, chapter_state::SetNotebook<S>> {
self._fields.4 = Option::Some(value.into());
ChapterBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: chapter_state::State> ChapterBuilder<'a, S> {
pub fn rating(mut self, value: impl Into<Option<ContentRating<'a>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_rating(mut self, value: Option<ContentRating<'a>>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S: chapter_state::State> ChapterBuilder<'a, S> {
pub fn tags(mut self, value: impl Into<Option<Tags<'a>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_tags(mut self, value: Option<Tags<'a>>) -> Self {
self._fields.6 = value;
self
}
}
impl<'a, S: chapter_state::State> ChapterBuilder<'a, S> {
pub fn title(mut self, value: impl Into<Option<Title<'a>>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_title(mut self, value: Option<Title<'a>>) -> Self {
self._fields.7 = value;
self
}
}
impl<'a, S> ChapterBuilder<'a, S>
where
S: chapter_state::State,
S::Authors: chapter_state::IsSet,
S::Notebook: chapter_state::IsSet,
S::EntryList: chapter_state::IsSet,
{
pub fn build(self) -> Chapter<'a> {
Chapter {
authors: self._fields.0.unwrap(),
content_warnings: self._fields.1,
created_at: self._fields.2,
entry_list: self._fields.3.unwrap(),
notebook: self._fields.4.unwrap(),
rating: self._fields.5,
tags: self._fields.6,
title: self._fields.7,
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Chapter<'a> {
Chapter {
authors: self._fields.0.unwrap(),
content_warnings: self._fields.1,
created_at: self._fields.2,
entry_list: self._fields.3.unwrap(),
notebook: self._fields.4.unwrap(),
rating: self._fields.5,
tags: self._fields.6,
title: self._fields.7,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_sh_weaver_notebook_chapter() -> 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("sh.weaver.notebook.chapter"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static("A grouping of entries in a notebook."),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("notebook"),
SmolStr::new_static("authors"),
SmolStr::new_static("entryList")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("authors"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("sh.weaver.actor.defs#author"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("contentWarnings"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static(
"sh.weaver.notebook.defs#contentWarnings",
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Client-declared timestamp when this was originally created.",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("entryList"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("notebook"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("rating"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static(
"sh.weaver.notebook.defs#contentRating",
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("tags"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("sh.weaver.notebook.defs#tags"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("sh.weaver.notebook.defs#title"),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}