Skip to main content

jacquard_api/pub_leaflet/blocks/
ordered_list.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: pub.leaflet.blocks.orderedList
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13
14#[allow(unused_imports)]
15use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
16use jacquard_derive::{IntoStatic, lexicon, open_union};
17use jacquard_lexicon::lexicon::LexiconDoc;
18use jacquard_lexicon::schema::LexiconSchema;
19
20#[allow(unused_imports)]
21use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
22use serde::{Serialize, Deserialize};
23use crate::pub_leaflet::blocks::header::Header;
24use crate::pub_leaflet::blocks::image::Image;
25use crate::pub_leaflet::blocks::text::Text;
26use crate::pub_leaflet::blocks::unordered_list::UnorderedList;
27use crate::pub_leaflet::blocks::ordered_list;
28
29#[lexicon]
30#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
31#[serde(rename_all = "camelCase")]
32pub struct ListItem<'a> {
33    ///Nested ordered list items. Mutually exclusive with unorderedListChildren; if both are present, children takes precedence.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    #[serde(borrow)]
36    pub children: Option<Vec<ordered_list::ListItem<'a>>>,
37    #[serde(borrow)]
38    pub content: ListItemContent<'a>,
39    ///A nested unordered list. Mutually exclusive with children; if both are present, children takes precedence.
40    #[serde(skip_serializing_if = "Option::is_none")]
41    #[serde(borrow)]
42    pub unordered_list_children: Option<UnorderedList<'a>>,
43}
44
45
46#[open_union]
47#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
48#[serde(tag = "$type", bound(deserialize = "'de: 'a"))]
49pub enum ListItemContent<'a> {
50    #[serde(rename = "pub.leaflet.blocks.text")]
51    Text(Box<Text<'a>>),
52    #[serde(rename = "pub.leaflet.blocks.header")]
53    Header(Box<Header<'a>>),
54    #[serde(rename = "pub.leaflet.blocks.image")]
55    Image(Box<Image<'a>>),
56}
57
58
59#[lexicon]
60#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
61#[serde(rename_all = "camelCase")]
62pub struct OrderedList<'a> {
63    #[serde(borrow)]
64    pub children: Vec<ordered_list::ListItem<'a>>,
65    ///The starting number for this ordered list. Defaults to 1 if not specified.
66    #[serde(skip_serializing_if = "Option::is_none")]
67    pub start_index: Option<i64>,
68}
69
70impl<'a> LexiconSchema for ListItem<'a> {
71    fn nsid() -> &'static str {
72        "pub.leaflet.blocks.orderedList"
73    }
74    fn def_name() -> &'static str {
75        "listItem"
76    }
77    fn lexicon_doc() -> LexiconDoc<'static> {
78        lexicon_doc_pub_leaflet_blocks_orderedList()
79    }
80    fn validate(&self) -> Result<(), ConstraintError> {
81        Ok(())
82    }
83}
84
85impl<'a> LexiconSchema for OrderedList<'a> {
86    fn nsid() -> &'static str {
87        "pub.leaflet.blocks.orderedList"
88    }
89    fn def_name() -> &'static str {
90        "main"
91    }
92    fn lexicon_doc() -> LexiconDoc<'static> {
93        lexicon_doc_pub_leaflet_blocks_orderedList()
94    }
95    fn validate(&self) -> Result<(), ConstraintError> {
96        Ok(())
97    }
98}
99
100pub mod list_item_state {
101
102    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
103    #[allow(unused)]
104    use ::core::marker::PhantomData;
105    mod sealed {
106        pub trait Sealed {}
107    }
108    /// State trait tracking which required fields have been set
109    pub trait State: sealed::Sealed {
110        type Content;
111    }
112    /// Empty state - all required fields are unset
113    pub struct Empty(());
114    impl sealed::Sealed for Empty {}
115    impl State for Empty {
116        type Content = Unset;
117    }
118    ///State transition - sets the `content` field to Set
119    pub struct SetContent<S: State = Empty>(PhantomData<fn() -> S>);
120    impl<S: State> sealed::Sealed for SetContent<S> {}
121    impl<S: State> State for SetContent<S> {
122        type Content = Set<members::content>;
123    }
124    /// Marker types for field names
125    #[allow(non_camel_case_types)]
126    pub mod members {
127        ///Marker type for the `content` field
128        pub struct content(());
129    }
130}
131
132/// Builder for constructing an instance of this type
133pub struct ListItemBuilder<'a, S: list_item_state::State> {
134    _state: PhantomData<fn() -> S>,
135    _fields: (
136        Option<Vec<ordered_list::ListItem<'a>>>,
137        Option<ListItemContent<'a>>,
138        Option<UnorderedList<'a>>,
139    ),
140    _lifetime: PhantomData<&'a ()>,
141}
142
143impl<'a> ListItem<'a> {
144    /// Create a new builder for this type
145    pub fn new() -> ListItemBuilder<'a, list_item_state::Empty> {
146        ListItemBuilder::new()
147    }
148}
149
150impl<'a> ListItemBuilder<'a, list_item_state::Empty> {
151    /// Create a new builder with all fields unset
152    pub fn new() -> Self {
153        ListItemBuilder {
154            _state: PhantomData,
155            _fields: (None, None, None),
156            _lifetime: PhantomData,
157        }
158    }
159}
160
161impl<'a, S: list_item_state::State> ListItemBuilder<'a, S> {
162    /// Set the `children` field (optional)
163    pub fn children(
164        mut self,
165        value: impl Into<Option<Vec<ordered_list::ListItem<'a>>>>,
166    ) -> Self {
167        self._fields.0 = value.into();
168        self
169    }
170    /// Set the `children` field to an Option value (optional)
171    pub fn maybe_children(
172        mut self,
173        value: Option<Vec<ordered_list::ListItem<'a>>>,
174    ) -> Self {
175        self._fields.0 = value;
176        self
177    }
178}
179
180impl<'a, S> ListItemBuilder<'a, S>
181where
182    S: list_item_state::State,
183    S::Content: list_item_state::IsUnset,
184{
185    /// Set the `content` field (required)
186    pub fn content(
187        mut self,
188        value: impl Into<ListItemContent<'a>>,
189    ) -> ListItemBuilder<'a, list_item_state::SetContent<S>> {
190        self._fields.1 = Option::Some(value.into());
191        ListItemBuilder {
192            _state: PhantomData,
193            _fields: self._fields,
194            _lifetime: PhantomData,
195        }
196    }
197}
198
199impl<'a, S: list_item_state::State> ListItemBuilder<'a, S> {
200    /// Set the `unorderedListChildren` field (optional)
201    pub fn unordered_list_children(
202        mut self,
203        value: impl Into<Option<UnorderedList<'a>>>,
204    ) -> Self {
205        self._fields.2 = value.into();
206        self
207    }
208    /// Set the `unorderedListChildren` field to an Option value (optional)
209    pub fn maybe_unordered_list_children(
210        mut self,
211        value: Option<UnorderedList<'a>>,
212    ) -> Self {
213        self._fields.2 = value;
214        self
215    }
216}
217
218impl<'a, S> ListItemBuilder<'a, S>
219where
220    S: list_item_state::State,
221    S::Content: list_item_state::IsSet,
222{
223    /// Build the final struct
224    pub fn build(self) -> ListItem<'a> {
225        ListItem {
226            children: self._fields.0,
227            content: self._fields.1.unwrap(),
228            unordered_list_children: self._fields.2,
229            extra_data: Default::default(),
230        }
231    }
232    /// Build the final struct with custom extra_data
233    pub fn build_with_data(
234        self,
235        extra_data: BTreeMap<
236            jacquard_common::deps::smol_str::SmolStr,
237            jacquard_common::types::value::Data<'a>,
238        >,
239    ) -> ListItem<'a> {
240        ListItem {
241            children: self._fields.0,
242            content: self._fields.1.unwrap(),
243            unordered_list_children: self._fields.2,
244            extra_data: Some(extra_data),
245        }
246    }
247}
248
249fn lexicon_doc_pub_leaflet_blocks_orderedList() -> LexiconDoc<'static> {
250    #[allow(unused_imports)]
251    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
252    use jacquard_lexicon::lexicon::*;
253    use alloc::collections::BTreeMap;
254    LexiconDoc {
255        lexicon: Lexicon::Lexicon1,
256        id: CowStr::new_static("pub.leaflet.blocks.orderedList"),
257        defs: {
258            let mut map = BTreeMap::new();
259            map.insert(
260                SmolStr::new_static("listItem"),
261                LexUserType::Object(LexObject {
262                    required: Some(vec![SmolStr::new_static("content")]),
263                    properties: {
264                        #[allow(unused_mut)]
265                        let mut map = BTreeMap::new();
266                        map.insert(
267                            SmolStr::new_static("children"),
268                            LexObjectProperty::Array(LexArray {
269                                description: Some(
270                                    CowStr::new_static(
271                                        "Nested ordered list items. Mutually exclusive with unorderedListChildren; if both are present, children takes precedence.",
272                                    ),
273                                ),
274                                items: LexArrayItem::Ref(LexRef {
275                                    r#ref: CowStr::new_static("#listItem"),
276                                    ..Default::default()
277                                }),
278                                ..Default::default()
279                            }),
280                        );
281                        map.insert(
282                            SmolStr::new_static("content"),
283                            LexObjectProperty::Union(LexRefUnion {
284                                refs: vec![
285                                    CowStr::new_static("pub.leaflet.blocks.text"),
286                                    CowStr::new_static("pub.leaflet.blocks.header"),
287                                    CowStr::new_static("pub.leaflet.blocks.image")
288                                ],
289                                ..Default::default()
290                            }),
291                        );
292                        map.insert(
293                            SmolStr::new_static("unorderedListChildren"),
294                            LexObjectProperty::Ref(LexRef {
295                                r#ref: CowStr::new_static(
296                                    "pub.leaflet.blocks.unorderedList",
297                                ),
298                                ..Default::default()
299                            }),
300                        );
301                        map
302                    },
303                    ..Default::default()
304                }),
305            );
306            map.insert(
307                SmolStr::new_static("main"),
308                LexUserType::Object(LexObject {
309                    required: Some(vec![SmolStr::new_static("children")]),
310                    properties: {
311                        #[allow(unused_mut)]
312                        let mut map = BTreeMap::new();
313                        map.insert(
314                            SmolStr::new_static("children"),
315                            LexObjectProperty::Array(LexArray {
316                                items: LexArrayItem::Ref(LexRef {
317                                    r#ref: CowStr::new_static("#listItem"),
318                                    ..Default::default()
319                                }),
320                                ..Default::default()
321                            }),
322                        );
323                        map.insert(
324                            SmolStr::new_static("startIndex"),
325                            LexObjectProperty::Integer(LexInteger {
326                                ..Default::default()
327                            }),
328                        );
329                        map
330                    },
331                    ..Default::default()
332                }),
333            );
334            map
335        },
336        ..Default::default()
337    }
338}
339
340pub mod ordered_list_state {
341
342    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
343    #[allow(unused)]
344    use ::core::marker::PhantomData;
345    mod sealed {
346        pub trait Sealed {}
347    }
348    /// State trait tracking which required fields have been set
349    pub trait State: sealed::Sealed {
350        type Children;
351    }
352    /// Empty state - all required fields are unset
353    pub struct Empty(());
354    impl sealed::Sealed for Empty {}
355    impl State for Empty {
356        type Children = Unset;
357    }
358    ///State transition - sets the `children` field to Set
359    pub struct SetChildren<S: State = Empty>(PhantomData<fn() -> S>);
360    impl<S: State> sealed::Sealed for SetChildren<S> {}
361    impl<S: State> State for SetChildren<S> {
362        type Children = Set<members::children>;
363    }
364    /// Marker types for field names
365    #[allow(non_camel_case_types)]
366    pub mod members {
367        ///Marker type for the `children` field
368        pub struct children(());
369    }
370}
371
372/// Builder for constructing an instance of this type
373pub struct OrderedListBuilder<'a, S: ordered_list_state::State> {
374    _state: PhantomData<fn() -> S>,
375    _fields: (Option<Vec<ordered_list::ListItem<'a>>>, Option<i64>),
376    _lifetime: PhantomData<&'a ()>,
377}
378
379impl<'a> OrderedList<'a> {
380    /// Create a new builder for this type
381    pub fn new() -> OrderedListBuilder<'a, ordered_list_state::Empty> {
382        OrderedListBuilder::new()
383    }
384}
385
386impl<'a> OrderedListBuilder<'a, ordered_list_state::Empty> {
387    /// Create a new builder with all fields unset
388    pub fn new() -> Self {
389        OrderedListBuilder {
390            _state: PhantomData,
391            _fields: (None, None),
392            _lifetime: PhantomData,
393        }
394    }
395}
396
397impl<'a, S> OrderedListBuilder<'a, S>
398where
399    S: ordered_list_state::State,
400    S::Children: ordered_list_state::IsUnset,
401{
402    /// Set the `children` field (required)
403    pub fn children(
404        mut self,
405        value: impl Into<Vec<ordered_list::ListItem<'a>>>,
406    ) -> OrderedListBuilder<'a, ordered_list_state::SetChildren<S>> {
407        self._fields.0 = Option::Some(value.into());
408        OrderedListBuilder {
409            _state: PhantomData,
410            _fields: self._fields,
411            _lifetime: PhantomData,
412        }
413    }
414}
415
416impl<'a, S: ordered_list_state::State> OrderedListBuilder<'a, S> {
417    /// Set the `startIndex` field (optional)
418    pub fn start_index(mut self, value: impl Into<Option<i64>>) -> Self {
419        self._fields.1 = value.into();
420        self
421    }
422    /// Set the `startIndex` field to an Option value (optional)
423    pub fn maybe_start_index(mut self, value: Option<i64>) -> Self {
424        self._fields.1 = value;
425        self
426    }
427}
428
429impl<'a, S> OrderedListBuilder<'a, S>
430where
431    S: ordered_list_state::State,
432    S::Children: ordered_list_state::IsSet,
433{
434    /// Build the final struct
435    pub fn build(self) -> OrderedList<'a> {
436        OrderedList {
437            children: self._fields.0.unwrap(),
438            start_index: self._fields.1,
439            extra_data: Default::default(),
440        }
441    }
442    /// Build the final struct with custom extra_data
443    pub fn build_with_data(
444        self,
445        extra_data: BTreeMap<
446            jacquard_common::deps::smol_str::SmolStr,
447            jacquard_common::types::value::Data<'a>,
448        >,
449    ) -> OrderedList<'a> {
450        OrderedList {
451            children: self._fields.0.unwrap(),
452            start_index: self._fields.1,
453            extra_data: Some(extra_data),
454        }
455    }
456}