Skip to main content

jacquard_api/games_gamesgamesgamesgames/
engine.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: games.gamesgamesgamesgames.engine
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
27use crate::games_gamesgamesgamesgames::MediaItem;
28use crate::games_gamesgamesgamesgames::Website;
29#[allow(unused_imports)]
30use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
31use serde::{Deserialize, Serialize};
32/// A game engine.
33
34#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
35#[serde(
36    rename_all = "camelCase",
37    rename = "games.gamesgamesgamesgames.engine",
38    tag = "$type",
39    bound(deserialize = "S: Deserialize<'de> + BosStr")
40)]
41pub struct Engine<S: BosStr = DefaultStr> {
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub companies: Option<Vec<AtUri<S>>>,
44    pub created_at: Datetime,
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub description: Option<S>,
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub media: Option<Vec<MediaItem<S>>>,
49    pub name: S,
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub platforms: Option<Vec<AtUri<S>>>,
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub websites: Option<Vec<Website<S>>>,
54    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
55    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
56}
57
58/// Typed wrapper for GetRecord response with this collection's record type.
59
60#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
61#[serde(rename_all = "camelCase")]
62pub struct EngineGetRecordOutput<S: BosStr = DefaultStr> {
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub cid: Option<Cid<S>>,
65    pub uri: AtUri<S>,
66    pub value: Engine<S>,
67}
68
69impl<S: BosStr> Engine<S> {
70    pub fn uri(uri: S) -> Result<RecordUri<S, EngineRecord>, UriError> {
71        RecordUri::try_from_uri(AtUri::new(uri)?)
72    }
73}
74
75/// Marker type for deserializing records from this collection.
76
77#[derive(Debug, Serialize, Deserialize)]
78pub struct EngineRecord;
79impl XrpcResp for EngineRecord {
80    const NSID: &'static str = "games.gamesgamesgamesgames.engine";
81    const ENCODING: &'static str = "application/json";
82    type Output<S: BosStr> = EngineGetRecordOutput<S>;
83    type Err = RecordError;
84}
85
86impl<S: BosStr> From<EngineGetRecordOutput<S>> for Engine<S> {
87    fn from(output: EngineGetRecordOutput<S>) -> Self {
88        output.value
89    }
90}
91
92impl<S: BosStr> Collection for Engine<S> {
93    const NSID: &'static str = "games.gamesgamesgamesgames.engine";
94    type Record = EngineRecord;
95}
96
97impl Collection for EngineRecord {
98    const NSID: &'static str = "games.gamesgamesgamesgames.engine";
99    type Record = EngineRecord;
100}
101
102impl<S: BosStr> LexiconSchema for Engine<S> {
103    fn nsid() -> &'static str {
104        "games.gamesgamesgamesgames.engine"
105    }
106    fn def_name() -> &'static str {
107        "main"
108    }
109    fn lexicon_doc() -> LexiconDoc<'static> {
110        lexicon_doc_games_gamesgamesgamesgames_engine()
111    }
112    fn validate(&self) -> Result<(), ConstraintError> {
113        Ok(())
114    }
115}
116
117pub mod engine_state {
118
119    pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
120    #[allow(unused)]
121    use ::core::marker::PhantomData;
122    mod sealed {
123        pub trait Sealed {}
124    }
125    /// State trait tracking which required fields have been set
126    pub trait State: sealed::Sealed {
127        type CreatedAt;
128        type Name;
129    }
130    /// Empty state - all required fields are unset
131    pub struct Empty(());
132    impl sealed::Sealed for Empty {}
133    impl State for Empty {
134        type CreatedAt = Unset;
135        type Name = Unset;
136    }
137    ///State transition - sets the `created_at` field to Set
138    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
139    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
140    impl<St: State> State for SetCreatedAt<St> {
141        type CreatedAt = Set<members::created_at>;
142        type Name = St::Name;
143    }
144    ///State transition - sets the `name` field to Set
145    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
146    impl<St: State> sealed::Sealed for SetName<St> {}
147    impl<St: State> State for SetName<St> {
148        type CreatedAt = St::CreatedAt;
149        type Name = Set<members::name>;
150    }
151    /// Marker types for field names
152    #[allow(non_camel_case_types)]
153    pub mod members {
154        ///Marker type for the `created_at` field
155        pub struct created_at(());
156        ///Marker type for the `name` field
157        pub struct name(());
158    }
159}
160
161/// Builder for constructing an instance of this type.
162pub struct EngineBuilder<St: engine_state::State, S: BosStr = DefaultStr> {
163    _state: PhantomData<fn() -> St>,
164    _fields: (
165        Option<Vec<AtUri<S>>>,
166        Option<Datetime>,
167        Option<S>,
168        Option<Vec<MediaItem<S>>>,
169        Option<S>,
170        Option<Vec<AtUri<S>>>,
171        Option<Vec<Website<S>>>,
172    ),
173    _type: PhantomData<fn() -> S>,
174}
175
176impl Engine<DefaultStr> {
177    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
178    pub fn new() -> EngineBuilder<engine_state::Empty, DefaultStr> {
179        EngineBuilder::new()
180    }
181}
182
183impl<S: BosStr> Engine<S> {
184    /// Create a new builder for this type
185    pub fn builder() -> EngineBuilder<engine_state::Empty, S> {
186        EngineBuilder::builder()
187    }
188}
189
190impl EngineBuilder<engine_state::Empty, DefaultStr> {
191    /// Create a new builder with all fields unset, using the default string type, if needed
192    pub fn new() -> Self {
193        EngineBuilder {
194            _state: PhantomData,
195            _fields: (None, None, None, None, None, None, None),
196            _type: PhantomData,
197        }
198    }
199}
200
201impl<S: BosStr> EngineBuilder<engine_state::Empty, S> {
202    /// Create a new builder with all fields unset
203    pub fn builder() -> Self {
204        EngineBuilder {
205            _state: PhantomData,
206            _fields: (None, None, None, None, None, None, None),
207            _type: PhantomData,
208        }
209    }
210}
211
212impl<St: engine_state::State, S: BosStr> EngineBuilder<St, S> {
213    /// Set the `companies` field (optional)
214    pub fn companies(mut self, value: impl Into<Option<Vec<AtUri<S>>>>) -> Self {
215        self._fields.0 = value.into();
216        self
217    }
218    /// Set the `companies` field to an Option value (optional)
219    pub fn maybe_companies(mut self, value: Option<Vec<AtUri<S>>>) -> Self {
220        self._fields.0 = value;
221        self
222    }
223}
224
225impl<St, S: BosStr> EngineBuilder<St, S>
226where
227    St: engine_state::State,
228    St::CreatedAt: engine_state::IsUnset,
229{
230    /// Set the `createdAt` field (required)
231    pub fn created_at(
232        mut self,
233        value: impl Into<Datetime>,
234    ) -> EngineBuilder<engine_state::SetCreatedAt<St>, S> {
235        self._fields.1 = Option::Some(value.into());
236        EngineBuilder {
237            _state: PhantomData,
238            _fields: self._fields,
239            _type: PhantomData,
240        }
241    }
242}
243
244impl<St: engine_state::State, S: BosStr> EngineBuilder<St, S> {
245    /// Set the `description` field (optional)
246    pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
247        self._fields.2 = value.into();
248        self
249    }
250    /// Set the `description` field to an Option value (optional)
251    pub fn maybe_description(mut self, value: Option<S>) -> Self {
252        self._fields.2 = value;
253        self
254    }
255}
256
257impl<St: engine_state::State, S: BosStr> EngineBuilder<St, S> {
258    /// Set the `media` field (optional)
259    pub fn media(mut self, value: impl Into<Option<Vec<MediaItem<S>>>>) -> Self {
260        self._fields.3 = value.into();
261        self
262    }
263    /// Set the `media` field to an Option value (optional)
264    pub fn maybe_media(mut self, value: Option<Vec<MediaItem<S>>>) -> Self {
265        self._fields.3 = value;
266        self
267    }
268}
269
270impl<St, S: BosStr> EngineBuilder<St, S>
271where
272    St: engine_state::State,
273    St::Name: engine_state::IsUnset,
274{
275    /// Set the `name` field (required)
276    pub fn name(mut self, value: impl Into<S>) -> EngineBuilder<engine_state::SetName<St>, S> {
277        self._fields.4 = Option::Some(value.into());
278        EngineBuilder {
279            _state: PhantomData,
280            _fields: self._fields,
281            _type: PhantomData,
282        }
283    }
284}
285
286impl<St: engine_state::State, S: BosStr> EngineBuilder<St, S> {
287    /// Set the `platforms` field (optional)
288    pub fn platforms(mut self, value: impl Into<Option<Vec<AtUri<S>>>>) -> Self {
289        self._fields.5 = value.into();
290        self
291    }
292    /// Set the `platforms` field to an Option value (optional)
293    pub fn maybe_platforms(mut self, value: Option<Vec<AtUri<S>>>) -> Self {
294        self._fields.5 = value;
295        self
296    }
297}
298
299impl<St: engine_state::State, S: BosStr> EngineBuilder<St, S> {
300    /// Set the `websites` field (optional)
301    pub fn websites(mut self, value: impl Into<Option<Vec<Website<S>>>>) -> Self {
302        self._fields.6 = value.into();
303        self
304    }
305    /// Set the `websites` field to an Option value (optional)
306    pub fn maybe_websites(mut self, value: Option<Vec<Website<S>>>) -> Self {
307        self._fields.6 = value;
308        self
309    }
310}
311
312impl<St, S: BosStr> EngineBuilder<St, S>
313where
314    St: engine_state::State,
315    St::CreatedAt: engine_state::IsSet,
316    St::Name: engine_state::IsSet,
317{
318    /// Build the final struct.
319    pub fn build(self) -> Engine<S> {
320        Engine {
321            companies: self._fields.0,
322            created_at: self._fields.1.unwrap(),
323            description: self._fields.2,
324            media: self._fields.3,
325            name: self._fields.4.unwrap(),
326            platforms: self._fields.5,
327            websites: self._fields.6,
328            extra_data: Default::default(),
329        }
330    }
331    /// Build the final struct with custom extra_data.
332    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Engine<S> {
333        Engine {
334            companies: self._fields.0,
335            created_at: self._fields.1.unwrap(),
336            description: self._fields.2,
337            media: self._fields.3,
338            name: self._fields.4.unwrap(),
339            platforms: self._fields.5,
340            websites: self._fields.6,
341            extra_data: Some(extra_data),
342        }
343    }
344}
345
346fn lexicon_doc_games_gamesgamesgamesgames_engine() -> LexiconDoc<'static> {
347    use alloc::collections::BTreeMap;
348    #[allow(unused_imports)]
349    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
350    use jacquard_lexicon::lexicon::*;
351    LexiconDoc {
352        lexicon: Lexicon::Lexicon1,
353        id: CowStr::new_static("games.gamesgamesgamesgames.engine"),
354        defs: {
355            let mut map = BTreeMap::new();
356            map.insert(
357                SmolStr::new_static("main"),
358                LexUserType::Record(LexRecord {
359                    description: Some(CowStr::new_static("A game engine.")),
360                    key: Some(CowStr::new_static("tid")),
361                    record: LexRecordRecord::Object(LexObject {
362                        required: Some(vec![
363                            SmolStr::new_static("name"),
364                            SmolStr::new_static("createdAt"),
365                        ]),
366                        properties: {
367                            #[allow(unused_mut)]
368                            let mut map = BTreeMap::new();
369                            map.insert(
370                                SmolStr::new_static("companies"),
371                                LexObjectProperty::Array(LexArray {
372                                    items: LexArrayItem::String(LexString {
373                                        format: Some(LexStringFormat::AtUri),
374                                        ..Default::default()
375                                    }),
376                                    ..Default::default()
377                                }),
378                            );
379                            map.insert(
380                                SmolStr::new_static("createdAt"),
381                                LexObjectProperty::String(LexString {
382                                    format: Some(LexStringFormat::Datetime),
383                                    ..Default::default()
384                                }),
385                            );
386                            map.insert(
387                                SmolStr::new_static("description"),
388                                LexObjectProperty::String(LexString {
389                                    ..Default::default()
390                                }),
391                            );
392                            map.insert(
393                                SmolStr::new_static("media"),
394                                LexObjectProperty::Array(LexArray {
395                                    items: LexArrayItem::Ref(LexRef {
396                                        r#ref: CowStr::new_static(
397                                            "games.gamesgamesgamesgames.defs#mediaItem",
398                                        ),
399                                        ..Default::default()
400                                    }),
401                                    ..Default::default()
402                                }),
403                            );
404                            map.insert(
405                                SmolStr::new_static("name"),
406                                LexObjectProperty::String(LexString {
407                                    ..Default::default()
408                                }),
409                            );
410                            map.insert(
411                                SmolStr::new_static("platforms"),
412                                LexObjectProperty::Array(LexArray {
413                                    items: LexArrayItem::String(LexString {
414                                        format: Some(LexStringFormat::AtUri),
415                                        ..Default::default()
416                                    }),
417                                    ..Default::default()
418                                }),
419                            );
420                            map.insert(
421                                SmolStr::new_static("websites"),
422                                LexObjectProperty::Array(LexArray {
423                                    items: LexArrayItem::Ref(LexRef {
424                                        r#ref: CowStr::new_static(
425                                            "games.gamesgamesgamesgames.defs#website",
426                                        ),
427                                        ..Default::default()
428                                    }),
429                                    ..Default::default()
430                                }),
431                            );
432                            map
433                        },
434                        ..Default::default()
435                    }),
436                    ..Default::default()
437                }),
438            );
439            map
440        },
441        ..Default::default()
442    }
443}