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::{CowStr, BosStr, 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::{Serialize, Deserialize};
30use crate::games_gamesgamesgamesgames::MediaItem;
31use crate::games_gamesgamesgamesgames::Website;
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::{Set, Unset, IsSet, IsUnset};
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(
277        mut self,
278        value: impl Into<S>,
279    ) -> EngineBuilder<engine_state::SetName<St>, S> {
280        self._fields.4 = Option::Some(value.into());
281        EngineBuilder {
282            _state: PhantomData,
283            _fields: self._fields,
284            _type: PhantomData,
285        }
286    }
287}
288
289impl<St: engine_state::State, S: BosStr> EngineBuilder<St, S> {
290    /// Set the `platforms` field (optional)
291    pub fn platforms(mut self, value: impl Into<Option<Vec<AtUri<S>>>>) -> Self {
292        self._fields.5 = value.into();
293        self
294    }
295    /// Set the `platforms` field to an Option value (optional)
296    pub fn maybe_platforms(mut self, value: Option<Vec<AtUri<S>>>) -> Self {
297        self._fields.5 = value;
298        self
299    }
300}
301
302impl<St: engine_state::State, S: BosStr> EngineBuilder<St, S> {
303    /// Set the `websites` field (optional)
304    pub fn websites(mut self, value: impl Into<Option<Vec<Website<S>>>>) -> Self {
305        self._fields.6 = value.into();
306        self
307    }
308    /// Set the `websites` field to an Option value (optional)
309    pub fn maybe_websites(mut self, value: Option<Vec<Website<S>>>) -> Self {
310        self._fields.6 = value;
311        self
312    }
313}
314
315impl<St, S: BosStr> EngineBuilder<St, S>
316where
317    St: engine_state::State,
318    St::CreatedAt: engine_state::IsSet,
319    St::Name: engine_state::IsSet,
320{
321    /// Build the final struct.
322    pub fn build(self) -> Engine<S> {
323        Engine {
324            companies: self._fields.0,
325            created_at: self._fields.1.unwrap(),
326            description: self._fields.2,
327            media: self._fields.3,
328            name: self._fields.4.unwrap(),
329            platforms: self._fields.5,
330            websites: self._fields.6,
331            extra_data: Default::default(),
332        }
333    }
334    /// Build the final struct with custom extra_data.
335    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Engine<S> {
336        Engine {
337            companies: self._fields.0,
338            created_at: self._fields.1.unwrap(),
339            description: self._fields.2,
340            media: self._fields.3,
341            name: self._fields.4.unwrap(),
342            platforms: self._fields.5,
343            websites: self._fields.6,
344            extra_data: Some(extra_data),
345        }
346    }
347}
348
349fn lexicon_doc_games_gamesgamesgamesgames_engine() -> LexiconDoc<'static> {
350    #[allow(unused_imports)]
351    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
352    use jacquard_lexicon::lexicon::*;
353    use alloc::collections::BTreeMap;
354    LexiconDoc {
355        lexicon: Lexicon::Lexicon1,
356        id: CowStr::new_static("games.gamesgamesgamesgames.engine"),
357        defs: {
358            let mut map = BTreeMap::new();
359            map.insert(
360                SmolStr::new_static("main"),
361                LexUserType::Record(LexRecord {
362                    description: Some(CowStr::new_static("A game engine.")),
363                    key: Some(CowStr::new_static("tid")),
364                    record: LexRecordRecord::Object(LexObject {
365                        required: Some(
366                            vec![
367                                SmolStr::new_static("name"),
368                                SmolStr::new_static("createdAt")
369                            ],
370                        ),
371                        properties: {
372                            #[allow(unused_mut)]
373                            let mut map = BTreeMap::new();
374                            map.insert(
375                                SmolStr::new_static("companies"),
376                                LexObjectProperty::Array(LexArray {
377                                    items: LexArrayItem::String(LexString {
378                                        format: Some(LexStringFormat::AtUri),
379                                        ..Default::default()
380                                    }),
381                                    ..Default::default()
382                                }),
383                            );
384                            map.insert(
385                                SmolStr::new_static("createdAt"),
386                                LexObjectProperty::String(LexString {
387                                    format: Some(LexStringFormat::Datetime),
388                                    ..Default::default()
389                                }),
390                            );
391                            map.insert(
392                                SmolStr::new_static("description"),
393                                LexObjectProperty::String(LexString {
394                                    ..Default::default()
395                                }),
396                            );
397                            map.insert(
398                                SmolStr::new_static("media"),
399                                LexObjectProperty::Array(LexArray {
400                                    items: LexArrayItem::Ref(LexRef {
401                                        r#ref: CowStr::new_static(
402                                            "games.gamesgamesgamesgames.defs#mediaItem",
403                                        ),
404                                        ..Default::default()
405                                    }),
406                                    ..Default::default()
407                                }),
408                            );
409                            map.insert(
410                                SmolStr::new_static("name"),
411                                LexObjectProperty::String(LexString {
412                                    ..Default::default()
413                                }),
414                            );
415                            map.insert(
416                                SmolStr::new_static("platforms"),
417                                LexObjectProperty::Array(LexArray {
418                                    items: LexArrayItem::String(LexString {
419                                        format: Some(LexStringFormat::AtUri),
420                                        ..Default::default()
421                                    }),
422                                    ..Default::default()
423                                }),
424                            );
425                            map.insert(
426                                SmolStr::new_static("websites"),
427                                LexObjectProperty::Array(LexArray {
428                                    items: LexArrayItem::Ref(LexRef {
429                                        r#ref: CowStr::new_static(
430                                            "games.gamesgamesgamesgames.defs#website",
431                                        ),
432                                        ..Default::default()
433                                    }),
434                                    ..Default::default()
435                                }),
436                            );
437                            map
438                        },
439                        ..Default::default()
440                    }),
441                    ..Default::default()
442                }),
443            );
444            map
445        },
446        ..Default::default()
447    }
448}