1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::types::collection::{Collection, RecordError};
18use jacquard_common::types::string::{AtUri, Cid, Datetime};
19use jacquard_common::types::uri::{RecordUri, UriError};
20use jacquard_common::xrpc::XrpcResp;
21use jacquard_derive::{IntoStatic, lexicon};
22use jacquard_lexicon::lexicon::LexiconDoc;
23use jacquard_lexicon::schema::LexiconSchema;
24
25#[allow(unused_imports)]
26use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
27use serde::{Serialize, Deserialize};
28use crate::com_atproto::repo::strong_ref::StrongRef;
29use crate::sh_weaver::actor::Author;
30use crate::sh_weaver::notebook::ContentRating;
31use crate::sh_weaver::notebook::ContentWarnings;
32use crate::sh_weaver::notebook::Tags;
33use crate::sh_weaver::notebook::Title;
34#[lexicon]
37#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
38#[serde(rename_all = "camelCase", rename = "sh.weaver.notebook.chapter", tag = "$type")]
39pub struct Chapter<'a> {
40 #[serde(borrow)]
41 pub authors: Vec<Author<'a>>,
42 #[serde(skip_serializing_if = "Option::is_none")]
43 #[serde(borrow)]
44 pub content_warnings: Option<ContentWarnings<'a>>,
45 #[serde(skip_serializing_if = "Option::is_none")]
47 pub created_at: Option<Datetime>,
48 #[serde(borrow)]
49 pub entry_list: Vec<StrongRef<'a>>,
50 #[serde(borrow)]
52 pub notebook: StrongRef<'a>,
53 #[serde(skip_serializing_if = "Option::is_none")]
54 #[serde(borrow)]
55 pub rating: Option<ContentRating<'a>>,
56 #[serde(skip_serializing_if = "Option::is_none")]
57 #[serde(borrow)]
58 pub tags: Option<Tags<'a>>,
59 #[serde(skip_serializing_if = "Option::is_none")]
60 #[serde(borrow)]
61 pub title: Option<Title<'a>>,
62}
63
64#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
67#[serde(rename_all = "camelCase")]
68pub struct ChapterGetRecordOutput<'a> {
69 #[serde(skip_serializing_if = "Option::is_none")]
70 #[serde(borrow)]
71 pub cid: Option<Cid<'a>>,
72 #[serde(borrow)]
73 pub uri: AtUri<'a>,
74 #[serde(borrow)]
75 pub value: Chapter<'a>,
76}
77
78impl<'a> Chapter<'a> {
79 pub fn uri(
80 uri: impl Into<CowStr<'a>>,
81 ) -> Result<RecordUri<'a, ChapterRecord>, UriError> {
82 RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
83 }
84}
85
86#[derive(Debug, Serialize, Deserialize)]
89pub struct ChapterRecord;
90impl XrpcResp for ChapterRecord {
91 const NSID: &'static str = "sh.weaver.notebook.chapter";
92 const ENCODING: &'static str = "application/json";
93 type Output<'de> = ChapterGetRecordOutput<'de>;
94 type Err<'de> = RecordError<'de>;
95}
96
97impl From<ChapterGetRecordOutput<'_>> for Chapter<'_> {
98 fn from(output: ChapterGetRecordOutput<'_>) -> Self {
99 use jacquard_common::IntoStatic;
100 output.value.into_static()
101 }
102}
103
104impl Collection for Chapter<'_> {
105 const NSID: &'static str = "sh.weaver.notebook.chapter";
106 type Record = ChapterRecord;
107}
108
109impl Collection for ChapterRecord {
110 const NSID: &'static str = "sh.weaver.notebook.chapter";
111 type Record = ChapterRecord;
112}
113
114impl<'a> LexiconSchema for Chapter<'a> {
115 fn nsid() -> &'static str {
116 "sh.weaver.notebook.chapter"
117 }
118 fn def_name() -> &'static str {
119 "main"
120 }
121 fn lexicon_doc() -> LexiconDoc<'static> {
122 lexicon_doc_sh_weaver_notebook_chapter()
123 }
124 fn validate(&self) -> Result<(), ConstraintError> {
125 Ok(())
126 }
127}
128
129pub mod chapter_state {
130
131 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
132 #[allow(unused)]
133 use ::core::marker::PhantomData;
134 mod sealed {
135 pub trait Sealed {}
136 }
137 pub trait State: sealed::Sealed {
139 type Authors;
140 type Notebook;
141 type EntryList;
142 }
143 pub struct Empty(());
145 impl sealed::Sealed for Empty {}
146 impl State for Empty {
147 type Authors = Unset;
148 type Notebook = Unset;
149 type EntryList = Unset;
150 }
151 pub struct SetAuthors<S: State = Empty>(PhantomData<fn() -> S>);
153 impl<S: State> sealed::Sealed for SetAuthors<S> {}
154 impl<S: State> State for SetAuthors<S> {
155 type Authors = Set<members::authors>;
156 type Notebook = S::Notebook;
157 type EntryList = S::EntryList;
158 }
159 pub struct SetNotebook<S: State = Empty>(PhantomData<fn() -> S>);
161 impl<S: State> sealed::Sealed for SetNotebook<S> {}
162 impl<S: State> State for SetNotebook<S> {
163 type Authors = S::Authors;
164 type Notebook = Set<members::notebook>;
165 type EntryList = S::EntryList;
166 }
167 pub struct SetEntryList<S: State = Empty>(PhantomData<fn() -> S>);
169 impl<S: State> sealed::Sealed for SetEntryList<S> {}
170 impl<S: State> State for SetEntryList<S> {
171 type Authors = S::Authors;
172 type Notebook = S::Notebook;
173 type EntryList = Set<members::entry_list>;
174 }
175 #[allow(non_camel_case_types)]
177 pub mod members {
178 pub struct authors(());
180 pub struct notebook(());
182 pub struct entry_list(());
184 }
185}
186
187pub struct ChapterBuilder<'a, S: chapter_state::State> {
189 _state: PhantomData<fn() -> S>,
190 _fields: (
191 Option<Vec<Author<'a>>>,
192 Option<ContentWarnings<'a>>,
193 Option<Datetime>,
194 Option<Vec<StrongRef<'a>>>,
195 Option<StrongRef<'a>>,
196 Option<ContentRating<'a>>,
197 Option<Tags<'a>>,
198 Option<Title<'a>>,
199 ),
200 _lifetime: PhantomData<&'a ()>,
201}
202
203impl<'a> Chapter<'a> {
204 pub fn new() -> ChapterBuilder<'a, chapter_state::Empty> {
206 ChapterBuilder::new()
207 }
208}
209
210impl<'a> ChapterBuilder<'a, chapter_state::Empty> {
211 pub fn new() -> Self {
213 ChapterBuilder {
214 _state: PhantomData,
215 _fields: (None, None, None, None, None, None, None, None),
216 _lifetime: PhantomData,
217 }
218 }
219}
220
221impl<'a, S> ChapterBuilder<'a, S>
222where
223 S: chapter_state::State,
224 S::Authors: chapter_state::IsUnset,
225{
226 pub fn authors(
228 mut self,
229 value: impl Into<Vec<Author<'a>>>,
230 ) -> ChapterBuilder<'a, chapter_state::SetAuthors<S>> {
231 self._fields.0 = Option::Some(value.into());
232 ChapterBuilder {
233 _state: PhantomData,
234 _fields: self._fields,
235 _lifetime: PhantomData,
236 }
237 }
238}
239
240impl<'a, S: chapter_state::State> ChapterBuilder<'a, S> {
241 pub fn content_warnings(
243 mut self,
244 value: impl Into<Option<ContentWarnings<'a>>>,
245 ) -> Self {
246 self._fields.1 = value.into();
247 self
248 }
249 pub fn maybe_content_warnings(mut self, value: Option<ContentWarnings<'a>>) -> Self {
251 self._fields.1 = value;
252 self
253 }
254}
255
256impl<'a, S: chapter_state::State> ChapterBuilder<'a, S> {
257 pub fn created_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
259 self._fields.2 = value.into();
260 self
261 }
262 pub fn maybe_created_at(mut self, value: Option<Datetime>) -> Self {
264 self._fields.2 = value;
265 self
266 }
267}
268
269impl<'a, S> ChapterBuilder<'a, S>
270where
271 S: chapter_state::State,
272 S::EntryList: chapter_state::IsUnset,
273{
274 pub fn entry_list(
276 mut self,
277 value: impl Into<Vec<StrongRef<'a>>>,
278 ) -> ChapterBuilder<'a, chapter_state::SetEntryList<S>> {
279 self._fields.3 = Option::Some(value.into());
280 ChapterBuilder {
281 _state: PhantomData,
282 _fields: self._fields,
283 _lifetime: PhantomData,
284 }
285 }
286}
287
288impl<'a, S> ChapterBuilder<'a, S>
289where
290 S: chapter_state::State,
291 S::Notebook: chapter_state::IsUnset,
292{
293 pub fn notebook(
295 mut self,
296 value: impl Into<StrongRef<'a>>,
297 ) -> ChapterBuilder<'a, chapter_state::SetNotebook<S>> {
298 self._fields.4 = Option::Some(value.into());
299 ChapterBuilder {
300 _state: PhantomData,
301 _fields: self._fields,
302 _lifetime: PhantomData,
303 }
304 }
305}
306
307impl<'a, S: chapter_state::State> ChapterBuilder<'a, S> {
308 pub fn rating(mut self, value: impl Into<Option<ContentRating<'a>>>) -> Self {
310 self._fields.5 = value.into();
311 self
312 }
313 pub fn maybe_rating(mut self, value: Option<ContentRating<'a>>) -> Self {
315 self._fields.5 = value;
316 self
317 }
318}
319
320impl<'a, S: chapter_state::State> ChapterBuilder<'a, S> {
321 pub fn tags(mut self, value: impl Into<Option<Tags<'a>>>) -> Self {
323 self._fields.6 = value.into();
324 self
325 }
326 pub fn maybe_tags(mut self, value: Option<Tags<'a>>) -> Self {
328 self._fields.6 = value;
329 self
330 }
331}
332
333impl<'a, S: chapter_state::State> ChapterBuilder<'a, S> {
334 pub fn title(mut self, value: impl Into<Option<Title<'a>>>) -> Self {
336 self._fields.7 = value.into();
337 self
338 }
339 pub fn maybe_title(mut self, value: Option<Title<'a>>) -> Self {
341 self._fields.7 = value;
342 self
343 }
344}
345
346impl<'a, S> ChapterBuilder<'a, S>
347where
348 S: chapter_state::State,
349 S::Authors: chapter_state::IsSet,
350 S::Notebook: chapter_state::IsSet,
351 S::EntryList: chapter_state::IsSet,
352{
353 pub fn build(self) -> Chapter<'a> {
355 Chapter {
356 authors: self._fields.0.unwrap(),
357 content_warnings: self._fields.1,
358 created_at: self._fields.2,
359 entry_list: self._fields.3.unwrap(),
360 notebook: self._fields.4.unwrap(),
361 rating: self._fields.5,
362 tags: self._fields.6,
363 title: self._fields.7,
364 extra_data: Default::default(),
365 }
366 }
367 pub fn build_with_data(
369 self,
370 extra_data: BTreeMap<
371 jacquard_common::deps::smol_str::SmolStr,
372 jacquard_common::types::value::Data<'a>,
373 >,
374 ) -> Chapter<'a> {
375 Chapter {
376 authors: self._fields.0.unwrap(),
377 content_warnings: self._fields.1,
378 created_at: self._fields.2,
379 entry_list: self._fields.3.unwrap(),
380 notebook: self._fields.4.unwrap(),
381 rating: self._fields.5,
382 tags: self._fields.6,
383 title: self._fields.7,
384 extra_data: Some(extra_data),
385 }
386 }
387}
388
389fn lexicon_doc_sh_weaver_notebook_chapter() -> LexiconDoc<'static> {
390 #[allow(unused_imports)]
391 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
392 use jacquard_lexicon::lexicon::*;
393 use alloc::collections::BTreeMap;
394 LexiconDoc {
395 lexicon: Lexicon::Lexicon1,
396 id: CowStr::new_static("sh.weaver.notebook.chapter"),
397 defs: {
398 let mut map = BTreeMap::new();
399 map.insert(
400 SmolStr::new_static("main"),
401 LexUserType::Record(LexRecord {
402 description: Some(
403 CowStr::new_static("A grouping of entries in a notebook."),
404 ),
405 key: Some(CowStr::new_static("tid")),
406 record: LexRecordRecord::Object(LexObject {
407 required: Some(
408 vec![
409 SmolStr::new_static("notebook"),
410 SmolStr::new_static("authors"),
411 SmolStr::new_static("entryList")
412 ],
413 ),
414 properties: {
415 #[allow(unused_mut)]
416 let mut map = BTreeMap::new();
417 map.insert(
418 SmolStr::new_static("authors"),
419 LexObjectProperty::Array(LexArray {
420 items: LexArrayItem::Ref(LexRef {
421 r#ref: CowStr::new_static("sh.weaver.actor.defs#author"),
422 ..Default::default()
423 }),
424 ..Default::default()
425 }),
426 );
427 map.insert(
428 SmolStr::new_static("contentWarnings"),
429 LexObjectProperty::Ref(LexRef {
430 r#ref: CowStr::new_static(
431 "sh.weaver.notebook.defs#contentWarnings",
432 ),
433 ..Default::default()
434 }),
435 );
436 map.insert(
437 SmolStr::new_static("createdAt"),
438 LexObjectProperty::String(LexString {
439 description: Some(
440 CowStr::new_static(
441 "Client-declared timestamp when this was originally created.",
442 ),
443 ),
444 format: Some(LexStringFormat::Datetime),
445 ..Default::default()
446 }),
447 );
448 map.insert(
449 SmolStr::new_static("entryList"),
450 LexObjectProperty::Array(LexArray {
451 items: LexArrayItem::Ref(LexRef {
452 r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
453 ..Default::default()
454 }),
455 ..Default::default()
456 }),
457 );
458 map.insert(
459 SmolStr::new_static("notebook"),
460 LexObjectProperty::Ref(LexRef {
461 r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
462 ..Default::default()
463 }),
464 );
465 map.insert(
466 SmolStr::new_static("rating"),
467 LexObjectProperty::Ref(LexRef {
468 r#ref: CowStr::new_static(
469 "sh.weaver.notebook.defs#contentRating",
470 ),
471 ..Default::default()
472 }),
473 );
474 map.insert(
475 SmolStr::new_static("tags"),
476 LexObjectProperty::Ref(LexRef {
477 r#ref: CowStr::new_static("sh.weaver.notebook.defs#tags"),
478 ..Default::default()
479 }),
480 );
481 map.insert(
482 SmolStr::new_static("title"),
483 LexObjectProperty::Ref(LexRef {
484 r#ref: CowStr::new_static("sh.weaver.notebook.defs#title"),
485 ..Default::default()
486 }),
487 );
488 map
489 },
490 ..Default::default()
491 }),
492 ..Default::default()
493 }),
494 );
495 map
496 },
497 ..Default::default()
498 }
499}