Skip to main content

jacquard_api/games_gamesgamesgamesgames/feed/
list.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: games.gamesgamesgamesgames.feed.list
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;
13use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::deps::smol_str::SmolStr;
18use jacquard_common::types::collection::{Collection, RecordError};
19use jacquard_common::types::string::{AtUri, Cid, Datetime};
20use jacquard_common::types::uri::{RecordUri, UriError};
21use jacquard_common::types::value::Data;
22use jacquard_common::xrpc::XrpcResp;
23use jacquard_derive::{IntoStatic, lexicon};
24use jacquard_lexicon::lexicon::LexiconDoc;
25use jacquard_lexicon::schema::LexiconSchema;
26
27#[allow(unused_imports)]
28use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
29use serde::{Deserialize, Serialize};
30
31#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
32#[serde(
33    rename_all = "camelCase",
34    rename = "games.gamesgamesgamesgames.feed.list",
35    tag = "$type",
36    bound(deserialize = "S: Deserialize<'de> + BosStr")
37)]
38pub struct List<S: BosStr = DefaultStr> {
39    pub created_at: Datetime,
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub description: Option<S>,
42    pub name: S,
43    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
44    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
45}
46
47/// Typed wrapper for GetRecord response with this collection's record type.
48
49#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
50#[serde(rename_all = "camelCase")]
51pub struct ListGetRecordOutput<S: BosStr = DefaultStr> {
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub cid: Option<Cid<S>>,
54    pub uri: AtUri<S>,
55    pub value: List<S>,
56}
57
58impl<S: BosStr> List<S> {
59    pub fn uri(uri: S) -> Result<RecordUri<S, ListRecord>, UriError> {
60        RecordUri::try_from_uri(AtUri::new(uri)?)
61    }
62}
63
64/// Marker type for deserializing records from this collection.
65
66#[derive(Debug, Serialize, Deserialize)]
67pub struct ListRecord;
68impl XrpcResp for ListRecord {
69    const NSID: &'static str = "games.gamesgamesgamesgames.feed.list";
70    const ENCODING: &'static str = "application/json";
71    type Output<S: BosStr> = ListGetRecordOutput<S>;
72    type Err = RecordError;
73}
74
75impl<S: BosStr> From<ListGetRecordOutput<S>> for List<S> {
76    fn from(output: ListGetRecordOutput<S>) -> Self {
77        output.value
78    }
79}
80
81impl<S: BosStr> Collection for List<S> {
82    const NSID: &'static str = "games.gamesgamesgamesgames.feed.list";
83    type Record = ListRecord;
84}
85
86impl Collection for ListRecord {
87    const NSID: &'static str = "games.gamesgamesgamesgames.feed.list";
88    type Record = ListRecord;
89}
90
91impl<S: BosStr> LexiconSchema for List<S> {
92    fn nsid() -> &'static str {
93        "games.gamesgamesgamesgames.feed.list"
94    }
95    fn def_name() -> &'static str {
96        "main"
97    }
98    fn lexicon_doc() -> LexiconDoc<'static> {
99        lexicon_doc_games_gamesgamesgamesgames_feed_list()
100    }
101    fn validate(&self) -> Result<(), ConstraintError> {
102        if let Some(ref value) = self.description {
103            #[allow(unused_comparisons)]
104            if <str>::len(value.as_ref()) > 500usize {
105                return Err(ConstraintError::MaxLength {
106                    path: ValidationPath::from_field("description"),
107                    max: 500usize,
108                    actual: <str>::len(value.as_ref()),
109                });
110            }
111        }
112        {
113            let value = &self.name;
114            #[allow(unused_comparisons)]
115            if <str>::len(value.as_ref()) > 100usize {
116                return Err(ConstraintError::MaxLength {
117                    path: ValidationPath::from_field("name"),
118                    max: 100usize,
119                    actual: <str>::len(value.as_ref()),
120                });
121            }
122        }
123        Ok(())
124    }
125}
126
127pub mod list_state {
128
129    pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
130    #[allow(unused)]
131    use ::core::marker::PhantomData;
132    mod sealed {
133        pub trait Sealed {}
134    }
135    /// State trait tracking which required fields have been set
136    pub trait State: sealed::Sealed {
137        type CreatedAt;
138        type Name;
139    }
140    /// Empty state - all required fields are unset
141    pub struct Empty(());
142    impl sealed::Sealed for Empty {}
143    impl State for Empty {
144        type CreatedAt = Unset;
145        type Name = Unset;
146    }
147    ///State transition - sets the `created_at` field to Set
148    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
149    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
150    impl<St: State> State for SetCreatedAt<St> {
151        type CreatedAt = Set<members::created_at>;
152        type Name = St::Name;
153    }
154    ///State transition - sets the `name` field to Set
155    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
156    impl<St: State> sealed::Sealed for SetName<St> {}
157    impl<St: State> State for SetName<St> {
158        type CreatedAt = St::CreatedAt;
159        type Name = Set<members::name>;
160    }
161    /// Marker types for field names
162    #[allow(non_camel_case_types)]
163    pub mod members {
164        ///Marker type for the `created_at` field
165        pub struct created_at(());
166        ///Marker type for the `name` field
167        pub struct name(());
168    }
169}
170
171/// Builder for constructing an instance of this type.
172pub struct ListBuilder<St: list_state::State, S: BosStr = DefaultStr> {
173    _state: PhantomData<fn() -> St>,
174    _fields: (Option<Datetime>, Option<S>, Option<S>),
175    _type: PhantomData<fn() -> S>,
176}
177
178impl List<DefaultStr> {
179    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
180    pub fn new() -> ListBuilder<list_state::Empty, DefaultStr> {
181        ListBuilder::new()
182    }
183}
184
185impl<S: BosStr> List<S> {
186    /// Create a new builder for this type
187    pub fn builder() -> ListBuilder<list_state::Empty, S> {
188        ListBuilder::builder()
189    }
190}
191
192impl ListBuilder<list_state::Empty, DefaultStr> {
193    /// Create a new builder with all fields unset, using the default string type, if needed
194    pub fn new() -> Self {
195        ListBuilder {
196            _state: PhantomData,
197            _fields: (None, None, None),
198            _type: PhantomData,
199        }
200    }
201}
202
203impl<S: BosStr> ListBuilder<list_state::Empty, S> {
204    /// Create a new builder with all fields unset
205    pub fn builder() -> Self {
206        ListBuilder {
207            _state: PhantomData,
208            _fields: (None, None, None),
209            _type: PhantomData,
210        }
211    }
212}
213
214impl<St, S: BosStr> ListBuilder<St, S>
215where
216    St: list_state::State,
217    St::CreatedAt: list_state::IsUnset,
218{
219    /// Set the `createdAt` field (required)
220    pub fn created_at(
221        mut self,
222        value: impl Into<Datetime>,
223    ) -> ListBuilder<list_state::SetCreatedAt<St>, S> {
224        self._fields.0 = Option::Some(value.into());
225        ListBuilder {
226            _state: PhantomData,
227            _fields: self._fields,
228            _type: PhantomData,
229        }
230    }
231}
232
233impl<St: list_state::State, S: BosStr> ListBuilder<St, S> {
234    /// Set the `description` field (optional)
235    pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
236        self._fields.1 = value.into();
237        self
238    }
239    /// Set the `description` field to an Option value (optional)
240    pub fn maybe_description(mut self, value: Option<S>) -> Self {
241        self._fields.1 = value;
242        self
243    }
244}
245
246impl<St, S: BosStr> ListBuilder<St, S>
247where
248    St: list_state::State,
249    St::Name: list_state::IsUnset,
250{
251    /// Set the `name` field (required)
252    pub fn name(mut self, value: impl Into<S>) -> ListBuilder<list_state::SetName<St>, S> {
253        self._fields.2 = Option::Some(value.into());
254        ListBuilder {
255            _state: PhantomData,
256            _fields: self._fields,
257            _type: PhantomData,
258        }
259    }
260}
261
262impl<St, S: BosStr> ListBuilder<St, S>
263where
264    St: list_state::State,
265    St::CreatedAt: list_state::IsSet,
266    St::Name: list_state::IsSet,
267{
268    /// Build the final struct.
269    pub fn build(self) -> List<S> {
270        List {
271            created_at: self._fields.0.unwrap(),
272            description: self._fields.1,
273            name: self._fields.2.unwrap(),
274            extra_data: Default::default(),
275        }
276    }
277    /// Build the final struct with custom extra_data.
278    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> List<S> {
279        List {
280            created_at: self._fields.0.unwrap(),
281            description: self._fields.1,
282            name: self._fields.2.unwrap(),
283            extra_data: Some(extra_data),
284        }
285    }
286}
287
288fn lexicon_doc_games_gamesgamesgamesgames_feed_list() -> LexiconDoc<'static> {
289    use alloc::collections::BTreeMap;
290    #[allow(unused_imports)]
291    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
292    use jacquard_lexicon::lexicon::*;
293    LexiconDoc {
294        lexicon: Lexicon::Lexicon1,
295        id: CowStr::new_static("games.gamesgamesgamesgames.feed.list"),
296        defs: {
297            let mut map = BTreeMap::new();
298            map.insert(
299                SmolStr::new_static("main"),
300                LexUserType::Record(LexRecord {
301                    key: Some(CowStr::new_static("tid")),
302                    record: LexRecordRecord::Object(LexObject {
303                        required: Some(vec![
304                            SmolStr::new_static("name"),
305                            SmolStr::new_static("createdAt"),
306                        ]),
307                        properties: {
308                            #[allow(unused_mut)]
309                            let mut map = BTreeMap::new();
310                            map.insert(
311                                SmolStr::new_static("createdAt"),
312                                LexObjectProperty::String(LexString {
313                                    format: Some(LexStringFormat::Datetime),
314                                    ..Default::default()
315                                }),
316                            );
317                            map.insert(
318                                SmolStr::new_static("description"),
319                                LexObjectProperty::String(LexString {
320                                    max_length: Some(500usize),
321                                    ..Default::default()
322                                }),
323                            );
324                            map.insert(
325                                SmolStr::new_static("name"),
326                                LexObjectProperty::String(LexString {
327                                    max_length: Some(100usize),
328                                    ..Default::default()
329                                }),
330                            );
331                            map
332                        },
333                        ..Default::default()
334                    }),
335                    ..Default::default()
336                }),
337            );
338            map
339        },
340        ..Default::default()
341    }
342}