Skip to main content

jacquard_api/tools_ozone/
set.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: tools.ozone.set.defs
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8pub mod add_values;
9pub mod delete_set;
10pub mod delete_values;
11pub mod get_values;
12pub mod query_sets;
13pub mod upsert_set;
14
15
16#[allow(unused_imports)]
17use alloc::collections::BTreeMap;
18
19#[allow(unused_imports)]
20use core::marker::PhantomData;
21use jacquard_common::CowStr;
22
23#[allow(unused_imports)]
24use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
25use jacquard_common::types::string::Datetime;
26use jacquard_derive::{IntoStatic, lexicon};
27use jacquard_lexicon::lexicon::LexiconDoc;
28use jacquard_lexicon::schema::LexiconSchema;
29
30#[allow(unused_imports)]
31use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
32use serde::{Serialize, Deserialize};
33
34#[lexicon]
35#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
36#[serde(rename_all = "camelCase")]
37pub struct Set<'a> {
38    #[serde(skip_serializing_if = "Option::is_none")]
39    #[serde(borrow)]
40    pub description: Option<CowStr<'a>>,
41    #[serde(borrow)]
42    pub name: CowStr<'a>,
43}
44
45
46#[lexicon]
47#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
48#[serde(rename_all = "camelCase")]
49pub struct SetView<'a> {
50    pub created_at: Datetime,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    #[serde(borrow)]
53    pub description: Option<CowStr<'a>>,
54    #[serde(borrow)]
55    pub name: CowStr<'a>,
56    pub set_size: i64,
57    pub updated_at: Datetime,
58}
59
60impl<'a> LexiconSchema for Set<'a> {
61    fn nsid() -> &'static str {
62        "tools.ozone.set.defs"
63    }
64    fn def_name() -> &'static str {
65        "set"
66    }
67    fn lexicon_doc() -> LexiconDoc<'static> {
68        lexicon_doc_tools_ozone_set_defs()
69    }
70    fn validate(&self) -> Result<(), ConstraintError> {
71        if let Some(ref value) = self.description {
72            #[allow(unused_comparisons)]
73            if <str>::len(value.as_ref()) > 10240usize {
74                return Err(ConstraintError::MaxLength {
75                    path: ValidationPath::from_field("description"),
76                    max: 10240usize,
77                    actual: <str>::len(value.as_ref()),
78                });
79            }
80        }
81        if let Some(ref value) = self.description {
82            {
83                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
84                if count > 1024usize {
85                    return Err(ConstraintError::MaxGraphemes {
86                        path: ValidationPath::from_field("description"),
87                        max: 1024usize,
88                        actual: count,
89                    });
90                }
91            }
92        }
93        {
94            let value = &self.name;
95            #[allow(unused_comparisons)]
96            if <str>::len(value.as_ref()) > 128usize {
97                return Err(ConstraintError::MaxLength {
98                    path: ValidationPath::from_field("name"),
99                    max: 128usize,
100                    actual: <str>::len(value.as_ref()),
101                });
102            }
103        }
104        {
105            let value = &self.name;
106            #[allow(unused_comparisons)]
107            if <str>::len(value.as_ref()) < 3usize {
108                return Err(ConstraintError::MinLength {
109                    path: ValidationPath::from_field("name"),
110                    min: 3usize,
111                    actual: <str>::len(value.as_ref()),
112                });
113            }
114        }
115        Ok(())
116    }
117}
118
119impl<'a> LexiconSchema for SetView<'a> {
120    fn nsid() -> &'static str {
121        "tools.ozone.set.defs"
122    }
123    fn def_name() -> &'static str {
124        "setView"
125    }
126    fn lexicon_doc() -> LexiconDoc<'static> {
127        lexicon_doc_tools_ozone_set_defs()
128    }
129    fn validate(&self) -> Result<(), ConstraintError> {
130        if let Some(ref value) = self.description {
131            #[allow(unused_comparisons)]
132            if <str>::len(value.as_ref()) > 10240usize {
133                return Err(ConstraintError::MaxLength {
134                    path: ValidationPath::from_field("description"),
135                    max: 10240usize,
136                    actual: <str>::len(value.as_ref()),
137                });
138            }
139        }
140        if let Some(ref value) = self.description {
141            {
142                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
143                if count > 1024usize {
144                    return Err(ConstraintError::MaxGraphemes {
145                        path: ValidationPath::from_field("description"),
146                        max: 1024usize,
147                        actual: count,
148                    });
149                }
150            }
151        }
152        {
153            let value = &self.name;
154            #[allow(unused_comparisons)]
155            if <str>::len(value.as_ref()) > 128usize {
156                return Err(ConstraintError::MaxLength {
157                    path: ValidationPath::from_field("name"),
158                    max: 128usize,
159                    actual: <str>::len(value.as_ref()),
160                });
161            }
162        }
163        {
164            let value = &self.name;
165            #[allow(unused_comparisons)]
166            if <str>::len(value.as_ref()) < 3usize {
167                return Err(ConstraintError::MinLength {
168                    path: ValidationPath::from_field("name"),
169                    min: 3usize,
170                    actual: <str>::len(value.as_ref()),
171                });
172            }
173        }
174        Ok(())
175    }
176}
177
178fn lexicon_doc_tools_ozone_set_defs() -> LexiconDoc<'static> {
179    #[allow(unused_imports)]
180    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
181    use jacquard_lexicon::lexicon::*;
182    use alloc::collections::BTreeMap;
183    LexiconDoc {
184        lexicon: Lexicon::Lexicon1,
185        id: CowStr::new_static("tools.ozone.set.defs"),
186        defs: {
187            let mut map = BTreeMap::new();
188            map.insert(
189                SmolStr::new_static("set"),
190                LexUserType::Object(LexObject {
191                    required: Some(vec![SmolStr::new_static("name")]),
192                    properties: {
193                        #[allow(unused_mut)]
194                        let mut map = BTreeMap::new();
195                        map.insert(
196                            SmolStr::new_static("description"),
197                            LexObjectProperty::String(LexString {
198                                max_length: Some(10240usize),
199                                max_graphemes: Some(1024usize),
200                                ..Default::default()
201                            }),
202                        );
203                        map.insert(
204                            SmolStr::new_static("name"),
205                            LexObjectProperty::String(LexString {
206                                min_length: Some(3usize),
207                                max_length: Some(128usize),
208                                ..Default::default()
209                            }),
210                        );
211                        map
212                    },
213                    ..Default::default()
214                }),
215            );
216            map.insert(
217                SmolStr::new_static("setView"),
218                LexUserType::Object(LexObject {
219                    required: Some(
220                        vec![
221                            SmolStr::new_static("name"), SmolStr::new_static("setSize"),
222                            SmolStr::new_static("createdAt"),
223                            SmolStr::new_static("updatedAt")
224                        ],
225                    ),
226                    properties: {
227                        #[allow(unused_mut)]
228                        let mut map = BTreeMap::new();
229                        map.insert(
230                            SmolStr::new_static("createdAt"),
231                            LexObjectProperty::String(LexString {
232                                format: Some(LexStringFormat::Datetime),
233                                ..Default::default()
234                            }),
235                        );
236                        map.insert(
237                            SmolStr::new_static("description"),
238                            LexObjectProperty::String(LexString {
239                                max_length: Some(10240usize),
240                                max_graphemes: Some(1024usize),
241                                ..Default::default()
242                            }),
243                        );
244                        map.insert(
245                            SmolStr::new_static("name"),
246                            LexObjectProperty::String(LexString {
247                                min_length: Some(3usize),
248                                max_length: Some(128usize),
249                                ..Default::default()
250                            }),
251                        );
252                        map.insert(
253                            SmolStr::new_static("setSize"),
254                            LexObjectProperty::Integer(LexInteger {
255                                ..Default::default()
256                            }),
257                        );
258                        map.insert(
259                            SmolStr::new_static("updatedAt"),
260                            LexObjectProperty::String(LexString {
261                                format: Some(LexStringFormat::Datetime),
262                                ..Default::default()
263                            }),
264                        );
265                        map
266                    },
267                    ..Default::default()
268                }),
269            );
270            map
271        },
272        ..Default::default()
273    }
274}
275
276pub mod set_view_state {
277
278    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
279    #[allow(unused)]
280    use ::core::marker::PhantomData;
281    mod sealed {
282        pub trait Sealed {}
283    }
284    /// State trait tracking which required fields have been set
285    pub trait State: sealed::Sealed {
286        type SetSize;
287        type CreatedAt;
288        type Name;
289        type UpdatedAt;
290    }
291    /// Empty state - all required fields are unset
292    pub struct Empty(());
293    impl sealed::Sealed for Empty {}
294    impl State for Empty {
295        type SetSize = Unset;
296        type CreatedAt = Unset;
297        type Name = Unset;
298        type UpdatedAt = Unset;
299    }
300    ///State transition - sets the `set_size` field to Set
301    pub struct SetSetSize<S: State = Empty>(PhantomData<fn() -> S>);
302    impl<S: State> sealed::Sealed for SetSetSize<S> {}
303    impl<S: State> State for SetSetSize<S> {
304        type SetSize = Set<members::set_size>;
305        type CreatedAt = S::CreatedAt;
306        type Name = S::Name;
307        type UpdatedAt = S::UpdatedAt;
308    }
309    ///State transition - sets the `created_at` field to Set
310    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
311    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
312    impl<S: State> State for SetCreatedAt<S> {
313        type SetSize = S::SetSize;
314        type CreatedAt = Set<members::created_at>;
315        type Name = S::Name;
316        type UpdatedAt = S::UpdatedAt;
317    }
318    ///State transition - sets the `name` field to Set
319    pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
320    impl<S: State> sealed::Sealed for SetName<S> {}
321    impl<S: State> State for SetName<S> {
322        type SetSize = S::SetSize;
323        type CreatedAt = S::CreatedAt;
324        type Name = Set<members::name>;
325        type UpdatedAt = S::UpdatedAt;
326    }
327    ///State transition - sets the `updated_at` field to Set
328    pub struct SetUpdatedAt<S: State = Empty>(PhantomData<fn() -> S>);
329    impl<S: State> sealed::Sealed for SetUpdatedAt<S> {}
330    impl<S: State> State for SetUpdatedAt<S> {
331        type SetSize = S::SetSize;
332        type CreatedAt = S::CreatedAt;
333        type Name = S::Name;
334        type UpdatedAt = Set<members::updated_at>;
335    }
336    /// Marker types for field names
337    #[allow(non_camel_case_types)]
338    pub mod members {
339        ///Marker type for the `set_size` field
340        pub struct set_size(());
341        ///Marker type for the `created_at` field
342        pub struct created_at(());
343        ///Marker type for the `name` field
344        pub struct name(());
345        ///Marker type for the `updated_at` field
346        pub struct updated_at(());
347    }
348}
349
350/// Builder for constructing an instance of this type
351pub struct SetViewBuilder<'a, S: set_view_state::State> {
352    _state: PhantomData<fn() -> S>,
353    _fields: (
354        Option<Datetime>,
355        Option<CowStr<'a>>,
356        Option<CowStr<'a>>,
357        Option<i64>,
358        Option<Datetime>,
359    ),
360    _lifetime: PhantomData<&'a ()>,
361}
362
363impl<'a> SetView<'a> {
364    /// Create a new builder for this type
365    pub fn new() -> SetViewBuilder<'a, set_view_state::Empty> {
366        SetViewBuilder::new()
367    }
368}
369
370impl<'a> SetViewBuilder<'a, set_view_state::Empty> {
371    /// Create a new builder with all fields unset
372    pub fn new() -> Self {
373        SetViewBuilder {
374            _state: PhantomData,
375            _fields: (None, None, None, None, None),
376            _lifetime: PhantomData,
377        }
378    }
379}
380
381impl<'a, S> SetViewBuilder<'a, S>
382where
383    S: set_view_state::State,
384    S::CreatedAt: set_view_state::IsUnset,
385{
386    /// Set the `createdAt` field (required)
387    pub fn created_at(
388        mut self,
389        value: impl Into<Datetime>,
390    ) -> SetViewBuilder<'a, set_view_state::SetCreatedAt<S>> {
391        self._fields.0 = Option::Some(value.into());
392        SetViewBuilder {
393            _state: PhantomData,
394            _fields: self._fields,
395            _lifetime: PhantomData,
396        }
397    }
398}
399
400impl<'a, S: set_view_state::State> SetViewBuilder<'a, S> {
401    /// Set the `description` field (optional)
402    pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
403        self._fields.1 = value.into();
404        self
405    }
406    /// Set the `description` field to an Option value (optional)
407    pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
408        self._fields.1 = value;
409        self
410    }
411}
412
413impl<'a, S> SetViewBuilder<'a, S>
414where
415    S: set_view_state::State,
416    S::Name: set_view_state::IsUnset,
417{
418    /// Set the `name` field (required)
419    pub fn name(
420        mut self,
421        value: impl Into<CowStr<'a>>,
422    ) -> SetViewBuilder<'a, set_view_state::SetName<S>> {
423        self._fields.2 = Option::Some(value.into());
424        SetViewBuilder {
425            _state: PhantomData,
426            _fields: self._fields,
427            _lifetime: PhantomData,
428        }
429    }
430}
431
432impl<'a, S> SetViewBuilder<'a, S>
433where
434    S: set_view_state::State,
435    S::SetSize: set_view_state::IsUnset,
436{
437    /// Set the `setSize` field (required)
438    pub fn set_size(
439        mut self,
440        value: impl Into<i64>,
441    ) -> SetViewBuilder<'a, set_view_state::SetSetSize<S>> {
442        self._fields.3 = Option::Some(value.into());
443        SetViewBuilder {
444            _state: PhantomData,
445            _fields: self._fields,
446            _lifetime: PhantomData,
447        }
448    }
449}
450
451impl<'a, S> SetViewBuilder<'a, S>
452where
453    S: set_view_state::State,
454    S::UpdatedAt: set_view_state::IsUnset,
455{
456    /// Set the `updatedAt` field (required)
457    pub fn updated_at(
458        mut self,
459        value: impl Into<Datetime>,
460    ) -> SetViewBuilder<'a, set_view_state::SetUpdatedAt<S>> {
461        self._fields.4 = Option::Some(value.into());
462        SetViewBuilder {
463            _state: PhantomData,
464            _fields: self._fields,
465            _lifetime: PhantomData,
466        }
467    }
468}
469
470impl<'a, S> SetViewBuilder<'a, S>
471where
472    S: set_view_state::State,
473    S::SetSize: set_view_state::IsSet,
474    S::CreatedAt: set_view_state::IsSet,
475    S::Name: set_view_state::IsSet,
476    S::UpdatedAt: set_view_state::IsSet,
477{
478    /// Build the final struct
479    pub fn build(self) -> SetView<'a> {
480        SetView {
481            created_at: self._fields.0.unwrap(),
482            description: self._fields.1,
483            name: self._fields.2.unwrap(),
484            set_size: self._fields.3.unwrap(),
485            updated_at: self._fields.4.unwrap(),
486            extra_data: Default::default(),
487        }
488    }
489    /// Build the final struct with custom extra_data
490    pub fn build_with_data(
491        self,
492        extra_data: BTreeMap<
493            jacquard_common::deps::smol_str::SmolStr,
494            jacquard_common::types::value::Data<'a>,
495        >,
496    ) -> SetView<'a> {
497        SetView {
498            created_at: self._fields.0.unwrap(),
499            description: self._fields.1,
500            name: self._fields.2.unwrap(),
501            set_size: self._fields.3.unwrap(),
502            updated_at: self._fields.4.unwrap(),
503            extra_data: Some(extra_data),
504        }
505    }
506}