jacquard_api/network_slices/waitlist/
invite.rs1#[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::{Did, 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#[lexicon]
31#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
32#[serde(
33 rename_all = "camelCase",
34 rename = "network.slices.waitlist.invite",
35 tag = "$type"
36)]
37pub struct Invite<'a> {
38 pub created_at: Datetime,
40 #[serde(borrow)]
42 pub did: Did<'a>,
43 #[serde(skip_serializing_if = "Option::is_none")]
45 pub expires_at: Option<Datetime>,
46 #[serde(borrow)]
48 pub slice: AtUri<'a>,
49}
50
51#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
54#[serde(rename_all = "camelCase")]
55pub struct InviteGetRecordOutput<'a> {
56 #[serde(skip_serializing_if = "Option::is_none")]
57 #[serde(borrow)]
58 pub cid: Option<Cid<'a>>,
59 #[serde(borrow)]
60 pub uri: AtUri<'a>,
61 #[serde(borrow)]
62 pub value: Invite<'a>,
63}
64
65impl<'a> Invite<'a> {
66 pub fn uri(
67 uri: impl Into<CowStr<'a>>,
68 ) -> Result<RecordUri<'a, InviteRecord>, UriError> {
69 RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
70 }
71}
72
73#[derive(Debug, Serialize, Deserialize)]
76pub struct InviteRecord;
77impl XrpcResp for InviteRecord {
78 const NSID: &'static str = "network.slices.waitlist.invite";
79 const ENCODING: &'static str = "application/json";
80 type Output<'de> = InviteGetRecordOutput<'de>;
81 type Err<'de> = RecordError<'de>;
82}
83
84impl From<InviteGetRecordOutput<'_>> for Invite<'_> {
85 fn from(output: InviteGetRecordOutput<'_>) -> Self {
86 use jacquard_common::IntoStatic;
87 output.value.into_static()
88 }
89}
90
91impl Collection for Invite<'_> {
92 const NSID: &'static str = "network.slices.waitlist.invite";
93 type Record = InviteRecord;
94}
95
96impl Collection for InviteRecord {
97 const NSID: &'static str = "network.slices.waitlist.invite";
98 type Record = InviteRecord;
99}
100
101impl<'a> LexiconSchema for Invite<'a> {
102 fn nsid() -> &'static str {
103 "network.slices.waitlist.invite"
104 }
105 fn def_name() -> &'static str {
106 "main"
107 }
108 fn lexicon_doc() -> LexiconDoc<'static> {
109 lexicon_doc_network_slices_waitlist_invite()
110 }
111 fn validate(&self) -> Result<(), ConstraintError> {
112 Ok(())
113 }
114}
115
116pub mod invite_state {
117
118 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
119 #[allow(unused)]
120 use ::core::marker::PhantomData;
121 mod sealed {
122 pub trait Sealed {}
123 }
124 pub trait State: sealed::Sealed {
126 type Slice;
127 type CreatedAt;
128 type Did;
129 }
130 pub struct Empty(());
132 impl sealed::Sealed for Empty {}
133 impl State for Empty {
134 type Slice = Unset;
135 type CreatedAt = Unset;
136 type Did = Unset;
137 }
138 pub struct SetSlice<S: State = Empty>(PhantomData<fn() -> S>);
140 impl<S: State> sealed::Sealed for SetSlice<S> {}
141 impl<S: State> State for SetSlice<S> {
142 type Slice = Set<members::slice>;
143 type CreatedAt = S::CreatedAt;
144 type Did = S::Did;
145 }
146 pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
148 impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
149 impl<S: State> State for SetCreatedAt<S> {
150 type Slice = S::Slice;
151 type CreatedAt = Set<members::created_at>;
152 type Did = S::Did;
153 }
154 pub struct SetDid<S: State = Empty>(PhantomData<fn() -> S>);
156 impl<S: State> sealed::Sealed for SetDid<S> {}
157 impl<S: State> State for SetDid<S> {
158 type Slice = S::Slice;
159 type CreatedAt = S::CreatedAt;
160 type Did = Set<members::did>;
161 }
162 #[allow(non_camel_case_types)]
164 pub mod members {
165 pub struct slice(());
167 pub struct created_at(());
169 pub struct did(());
171 }
172}
173
174pub struct InviteBuilder<'a, S: invite_state::State> {
176 _state: PhantomData<fn() -> S>,
177 _fields: (Option<Datetime>, Option<Did<'a>>, Option<Datetime>, Option<AtUri<'a>>),
178 _lifetime: PhantomData<&'a ()>,
179}
180
181impl<'a> Invite<'a> {
182 pub fn new() -> InviteBuilder<'a, invite_state::Empty> {
184 InviteBuilder::new()
185 }
186}
187
188impl<'a> InviteBuilder<'a, invite_state::Empty> {
189 pub fn new() -> Self {
191 InviteBuilder {
192 _state: PhantomData,
193 _fields: (None, None, None, None),
194 _lifetime: PhantomData,
195 }
196 }
197}
198
199impl<'a, S> InviteBuilder<'a, S>
200where
201 S: invite_state::State,
202 S::CreatedAt: invite_state::IsUnset,
203{
204 pub fn created_at(
206 mut self,
207 value: impl Into<Datetime>,
208 ) -> InviteBuilder<'a, invite_state::SetCreatedAt<S>> {
209 self._fields.0 = Option::Some(value.into());
210 InviteBuilder {
211 _state: PhantomData,
212 _fields: self._fields,
213 _lifetime: PhantomData,
214 }
215 }
216}
217
218impl<'a, S> InviteBuilder<'a, S>
219where
220 S: invite_state::State,
221 S::Did: invite_state::IsUnset,
222{
223 pub fn did(
225 mut self,
226 value: impl Into<Did<'a>>,
227 ) -> InviteBuilder<'a, invite_state::SetDid<S>> {
228 self._fields.1 = Option::Some(value.into());
229 InviteBuilder {
230 _state: PhantomData,
231 _fields: self._fields,
232 _lifetime: PhantomData,
233 }
234 }
235}
236
237impl<'a, S: invite_state::State> InviteBuilder<'a, S> {
238 pub fn expires_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
240 self._fields.2 = value.into();
241 self
242 }
243 pub fn maybe_expires_at(mut self, value: Option<Datetime>) -> Self {
245 self._fields.2 = value;
246 self
247 }
248}
249
250impl<'a, S> InviteBuilder<'a, S>
251where
252 S: invite_state::State,
253 S::Slice: invite_state::IsUnset,
254{
255 pub fn slice(
257 mut self,
258 value: impl Into<AtUri<'a>>,
259 ) -> InviteBuilder<'a, invite_state::SetSlice<S>> {
260 self._fields.3 = Option::Some(value.into());
261 InviteBuilder {
262 _state: PhantomData,
263 _fields: self._fields,
264 _lifetime: PhantomData,
265 }
266 }
267}
268
269impl<'a, S> InviteBuilder<'a, S>
270where
271 S: invite_state::State,
272 S::Slice: invite_state::IsSet,
273 S::CreatedAt: invite_state::IsSet,
274 S::Did: invite_state::IsSet,
275{
276 pub fn build(self) -> Invite<'a> {
278 Invite {
279 created_at: self._fields.0.unwrap(),
280 did: self._fields.1.unwrap(),
281 expires_at: self._fields.2,
282 slice: self._fields.3.unwrap(),
283 extra_data: Default::default(),
284 }
285 }
286 pub fn build_with_data(
288 self,
289 extra_data: BTreeMap<
290 jacquard_common::deps::smol_str::SmolStr,
291 jacquard_common::types::value::Data<'a>,
292 >,
293 ) -> Invite<'a> {
294 Invite {
295 created_at: self._fields.0.unwrap(),
296 did: self._fields.1.unwrap(),
297 expires_at: self._fields.2,
298 slice: self._fields.3.unwrap(),
299 extra_data: Some(extra_data),
300 }
301 }
302}
303
304fn lexicon_doc_network_slices_waitlist_invite() -> LexiconDoc<'static> {
305 #[allow(unused_imports)]
306 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
307 use jacquard_lexicon::lexicon::*;
308 use alloc::collections::BTreeMap;
309 LexiconDoc {
310 lexicon: Lexicon::Lexicon1,
311 id: CowStr::new_static("network.slices.waitlist.invite"),
312 defs: {
313 let mut map = BTreeMap::new();
314 map.insert(
315 SmolStr::new_static("main"),
316 LexUserType::Record(LexRecord {
317 description: Some(
318 CowStr::new_static(
319 "An invite granting a DID access, created by the slice owner",
320 ),
321 ),
322 key: Some(CowStr::new_static("tid")),
323 record: LexRecordRecord::Object(LexObject {
324 required: Some(
325 vec![
326 SmolStr::new_static("did"), SmolStr::new_static("slice"),
327 SmolStr::new_static("createdAt")
328 ],
329 ),
330 properties: {
331 #[allow(unused_mut)]
332 let mut map = BTreeMap::new();
333 map.insert(
334 SmolStr::new_static("createdAt"),
335 LexObjectProperty::String(LexString {
336 description: Some(
337 CowStr::new_static("When this invitation was created"),
338 ),
339 format: Some(LexStringFormat::Datetime),
340 ..Default::default()
341 }),
342 );
343 map.insert(
344 SmolStr::new_static("did"),
345 LexObjectProperty::String(LexString {
346 description: Some(
347 CowStr::new_static("The DID being invited"),
348 ),
349 format: Some(LexStringFormat::Did),
350 ..Default::default()
351 }),
352 );
353 map.insert(
354 SmolStr::new_static("expiresAt"),
355 LexObjectProperty::String(LexString {
356 description: Some(
357 CowStr::new_static(
358 "Optional expiration date for this invitation",
359 ),
360 ),
361 format: Some(LexStringFormat::Datetime),
362 ..Default::default()
363 }),
364 );
365 map.insert(
366 SmolStr::new_static("slice"),
367 LexObjectProperty::String(LexString {
368 description: Some(
369 CowStr::new_static(
370 "The AT URI of the slice this invite is for",
371 ),
372 ),
373 format: Some(LexStringFormat::AtUri),
374 ..Default::default()
375 }),
376 );
377 map
378 },
379 ..Default::default()
380 }),
381 ..Default::default()
382 }),
383 );
384 map
385 },
386 ..Default::default()
387 }
388}