Skip to main content

jacquard_api/network_slices/waitlist/
request.rs

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