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