Skip to main content

jacquard_api/place_stream/chat/
profile.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: place.stream.chat.profile
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};
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};
28use crate::place_stream::chat::profile;
29/// Customizations for the color of a user's name in chat
30
31#[lexicon]
32#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
33#[serde(rename_all = "camelCase")]
34pub struct Color<'a> {
35    pub blue: i64,
36    pub green: i64,
37    pub red: i64,
38}
39
40/// Record containing customizations for a user's chat profile.
41
42#[lexicon]
43#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
44#[serde(rename_all = "camelCase", rename = "place.stream.chat.profile", tag = "$type")]
45pub struct Profile<'a> {
46    #[serde(skip_serializing_if = "Option::is_none")]
47    #[serde(borrow)]
48    pub color: Option<profile::Color<'a>>,
49}
50
51/// Typed wrapper for GetRecord response with this collection's record type.
52
53#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
54#[serde(rename_all = "camelCase")]
55pub struct ProfileGetRecordOutput<'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: Profile<'a>,
63}
64
65impl<'a> Profile<'a> {
66    pub fn uri(
67        uri: impl Into<CowStr<'a>>,
68    ) -> Result<RecordUri<'a, ProfileRecord>, UriError> {
69        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
70    }
71}
72
73impl<'a> LexiconSchema for Color<'a> {
74    fn nsid() -> &'static str {
75        "place.stream.chat.profile"
76    }
77    fn def_name() -> &'static str {
78        "color"
79    }
80    fn lexicon_doc() -> LexiconDoc<'static> {
81        lexicon_doc_place_stream_chat_profile()
82    }
83    fn validate(&self) -> Result<(), ConstraintError> {
84        {
85            let value = &self.blue;
86            if *value > 255i64 {
87                return Err(ConstraintError::Maximum {
88                    path: ValidationPath::from_field("blue"),
89                    max: 255i64,
90                    actual: *value,
91                });
92            }
93        }
94        {
95            let value = &self.blue;
96            if *value < 0i64 {
97                return Err(ConstraintError::Minimum {
98                    path: ValidationPath::from_field("blue"),
99                    min: 0i64,
100                    actual: *value,
101                });
102            }
103        }
104        {
105            let value = &self.green;
106            if *value > 255i64 {
107                return Err(ConstraintError::Maximum {
108                    path: ValidationPath::from_field("green"),
109                    max: 255i64,
110                    actual: *value,
111                });
112            }
113        }
114        {
115            let value = &self.green;
116            if *value < 0i64 {
117                return Err(ConstraintError::Minimum {
118                    path: ValidationPath::from_field("green"),
119                    min: 0i64,
120                    actual: *value,
121                });
122            }
123        }
124        {
125            let value = &self.red;
126            if *value > 255i64 {
127                return Err(ConstraintError::Maximum {
128                    path: ValidationPath::from_field("red"),
129                    max: 255i64,
130                    actual: *value,
131                });
132            }
133        }
134        {
135            let value = &self.red;
136            if *value < 0i64 {
137                return Err(ConstraintError::Minimum {
138                    path: ValidationPath::from_field("red"),
139                    min: 0i64,
140                    actual: *value,
141                });
142            }
143        }
144        Ok(())
145    }
146}
147
148/// Marker type for deserializing records from this collection.
149
150#[derive(Debug, Serialize, Deserialize)]
151pub struct ProfileRecord;
152impl XrpcResp for ProfileRecord {
153    const NSID: &'static str = "place.stream.chat.profile";
154    const ENCODING: &'static str = "application/json";
155    type Output<'de> = ProfileGetRecordOutput<'de>;
156    type Err<'de> = RecordError<'de>;
157}
158
159impl From<ProfileGetRecordOutput<'_>> for Profile<'_> {
160    fn from(output: ProfileGetRecordOutput<'_>) -> Self {
161        use jacquard_common::IntoStatic;
162        output.value.into_static()
163    }
164}
165
166impl Collection for Profile<'_> {
167    const NSID: &'static str = "place.stream.chat.profile";
168    type Record = ProfileRecord;
169}
170
171impl Collection for ProfileRecord {
172    const NSID: &'static str = "place.stream.chat.profile";
173    type Record = ProfileRecord;
174}
175
176impl<'a> LexiconSchema for Profile<'a> {
177    fn nsid() -> &'static str {
178        "place.stream.chat.profile"
179    }
180    fn def_name() -> &'static str {
181        "main"
182    }
183    fn lexicon_doc() -> LexiconDoc<'static> {
184        lexicon_doc_place_stream_chat_profile()
185    }
186    fn validate(&self) -> Result<(), ConstraintError> {
187        Ok(())
188    }
189}
190
191pub mod color_state {
192
193    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
194    #[allow(unused)]
195    use ::core::marker::PhantomData;
196    mod sealed {
197        pub trait Sealed {}
198    }
199    /// State trait tracking which required fields have been set
200    pub trait State: sealed::Sealed {
201        type Blue;
202        type Green;
203        type Red;
204    }
205    /// Empty state - all required fields are unset
206    pub struct Empty(());
207    impl sealed::Sealed for Empty {}
208    impl State for Empty {
209        type Blue = Unset;
210        type Green = Unset;
211        type Red = Unset;
212    }
213    ///State transition - sets the `blue` field to Set
214    pub struct SetBlue<S: State = Empty>(PhantomData<fn() -> S>);
215    impl<S: State> sealed::Sealed for SetBlue<S> {}
216    impl<S: State> State for SetBlue<S> {
217        type Blue = Set<members::blue>;
218        type Green = S::Green;
219        type Red = S::Red;
220    }
221    ///State transition - sets the `green` field to Set
222    pub struct SetGreen<S: State = Empty>(PhantomData<fn() -> S>);
223    impl<S: State> sealed::Sealed for SetGreen<S> {}
224    impl<S: State> State for SetGreen<S> {
225        type Blue = S::Blue;
226        type Green = Set<members::green>;
227        type Red = S::Red;
228    }
229    ///State transition - sets the `red` field to Set
230    pub struct SetRed<S: State = Empty>(PhantomData<fn() -> S>);
231    impl<S: State> sealed::Sealed for SetRed<S> {}
232    impl<S: State> State for SetRed<S> {
233        type Blue = S::Blue;
234        type Green = S::Green;
235        type Red = Set<members::red>;
236    }
237    /// Marker types for field names
238    #[allow(non_camel_case_types)]
239    pub mod members {
240        ///Marker type for the `blue` field
241        pub struct blue(());
242        ///Marker type for the `green` field
243        pub struct green(());
244        ///Marker type for the `red` field
245        pub struct red(());
246    }
247}
248
249/// Builder for constructing an instance of this type
250pub struct ColorBuilder<'a, S: color_state::State> {
251    _state: PhantomData<fn() -> S>,
252    _fields: (Option<i64>, Option<i64>, Option<i64>),
253    _lifetime: PhantomData<&'a ()>,
254}
255
256impl<'a> Color<'a> {
257    /// Create a new builder for this type
258    pub fn new() -> ColorBuilder<'a, color_state::Empty> {
259        ColorBuilder::new()
260    }
261}
262
263impl<'a> ColorBuilder<'a, color_state::Empty> {
264    /// Create a new builder with all fields unset
265    pub fn new() -> Self {
266        ColorBuilder {
267            _state: PhantomData,
268            _fields: (None, None, None),
269            _lifetime: PhantomData,
270        }
271    }
272}
273
274impl<'a, S> ColorBuilder<'a, S>
275where
276    S: color_state::State,
277    S::Blue: color_state::IsUnset,
278{
279    /// Set the `blue` field (required)
280    pub fn blue(
281        mut self,
282        value: impl Into<i64>,
283    ) -> ColorBuilder<'a, color_state::SetBlue<S>> {
284        self._fields.0 = Option::Some(value.into());
285        ColorBuilder {
286            _state: PhantomData,
287            _fields: self._fields,
288            _lifetime: PhantomData,
289        }
290    }
291}
292
293impl<'a, S> ColorBuilder<'a, S>
294where
295    S: color_state::State,
296    S::Green: color_state::IsUnset,
297{
298    /// Set the `green` field (required)
299    pub fn green(
300        mut self,
301        value: impl Into<i64>,
302    ) -> ColorBuilder<'a, color_state::SetGreen<S>> {
303        self._fields.1 = Option::Some(value.into());
304        ColorBuilder {
305            _state: PhantomData,
306            _fields: self._fields,
307            _lifetime: PhantomData,
308        }
309    }
310}
311
312impl<'a, S> ColorBuilder<'a, S>
313where
314    S: color_state::State,
315    S::Red: color_state::IsUnset,
316{
317    /// Set the `red` field (required)
318    pub fn red(
319        mut self,
320        value: impl Into<i64>,
321    ) -> ColorBuilder<'a, color_state::SetRed<S>> {
322        self._fields.2 = Option::Some(value.into());
323        ColorBuilder {
324            _state: PhantomData,
325            _fields: self._fields,
326            _lifetime: PhantomData,
327        }
328    }
329}
330
331impl<'a, S> ColorBuilder<'a, S>
332where
333    S: color_state::State,
334    S::Blue: color_state::IsSet,
335    S::Green: color_state::IsSet,
336    S::Red: color_state::IsSet,
337{
338    /// Build the final struct
339    pub fn build(self) -> Color<'a> {
340        Color {
341            blue: self._fields.0.unwrap(),
342            green: self._fields.1.unwrap(),
343            red: self._fields.2.unwrap(),
344            extra_data: Default::default(),
345        }
346    }
347    /// Build the final struct with custom extra_data
348    pub fn build_with_data(
349        self,
350        extra_data: BTreeMap<
351            jacquard_common::deps::smol_str::SmolStr,
352            jacquard_common::types::value::Data<'a>,
353        >,
354    ) -> Color<'a> {
355        Color {
356            blue: self._fields.0.unwrap(),
357            green: self._fields.1.unwrap(),
358            red: self._fields.2.unwrap(),
359            extra_data: Some(extra_data),
360        }
361    }
362}
363
364fn lexicon_doc_place_stream_chat_profile() -> LexiconDoc<'static> {
365    #[allow(unused_imports)]
366    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
367    use jacquard_lexicon::lexicon::*;
368    use alloc::collections::BTreeMap;
369    LexiconDoc {
370        lexicon: Lexicon::Lexicon1,
371        id: CowStr::new_static("place.stream.chat.profile"),
372        defs: {
373            let mut map = BTreeMap::new();
374            map.insert(
375                SmolStr::new_static("color"),
376                LexUserType::Object(LexObject {
377                    description: Some(
378                        CowStr::new_static(
379                            "Customizations for the color of a user's name in chat",
380                        ),
381                    ),
382                    required: Some(
383                        vec![
384                            SmolStr::new_static("red"), SmolStr::new_static("green"),
385                            SmolStr::new_static("blue")
386                        ],
387                    ),
388                    properties: {
389                        #[allow(unused_mut)]
390                        let mut map = BTreeMap::new();
391                        map.insert(
392                            SmolStr::new_static("blue"),
393                            LexObjectProperty::Integer(LexInteger {
394                                minimum: Some(0i64),
395                                maximum: Some(255i64),
396                                ..Default::default()
397                            }),
398                        );
399                        map.insert(
400                            SmolStr::new_static("green"),
401                            LexObjectProperty::Integer(LexInteger {
402                                minimum: Some(0i64),
403                                maximum: Some(255i64),
404                                ..Default::default()
405                            }),
406                        );
407                        map.insert(
408                            SmolStr::new_static("red"),
409                            LexObjectProperty::Integer(LexInteger {
410                                minimum: Some(0i64),
411                                maximum: Some(255i64),
412                                ..Default::default()
413                            }),
414                        );
415                        map
416                    },
417                    ..Default::default()
418                }),
419            );
420            map.insert(
421                SmolStr::new_static("main"),
422                LexUserType::Record(LexRecord {
423                    description: Some(
424                        CowStr::new_static(
425                            "Record containing customizations for a user's chat profile.",
426                        ),
427                    ),
428                    key: Some(CowStr::new_static("literal:self")),
429                    record: LexRecordRecord::Object(LexObject {
430                        properties: {
431                            #[allow(unused_mut)]
432                            let mut map = BTreeMap::new();
433                            map.insert(
434                                SmolStr::new_static("color"),
435                                LexObjectProperty::Ref(LexRef {
436                                    r#ref: CowStr::new_static("#color"),
437                                    ..Default::default()
438                                }),
439                            );
440                            map
441                        },
442                        ..Default::default()
443                    }),
444                    ..Default::default()
445                }),
446            );
447            map
448        },
449        ..Default::default()
450    }
451}
452
453pub mod profile_state {
454
455    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
456    #[allow(unused)]
457    use ::core::marker::PhantomData;
458    mod sealed {
459        pub trait Sealed {}
460    }
461    /// State trait tracking which required fields have been set
462    pub trait State: sealed::Sealed {}
463    /// Empty state - all required fields are unset
464    pub struct Empty(());
465    impl sealed::Sealed for Empty {}
466    impl State for Empty {}
467    /// Marker types for field names
468    #[allow(non_camel_case_types)]
469    pub mod members {}
470}
471
472/// Builder for constructing an instance of this type
473pub struct ProfileBuilder<'a, S: profile_state::State> {
474    _state: PhantomData<fn() -> S>,
475    _fields: (Option<profile::Color<'a>>,),
476    _lifetime: PhantomData<&'a ()>,
477}
478
479impl<'a> Profile<'a> {
480    /// Create a new builder for this type
481    pub fn new() -> ProfileBuilder<'a, profile_state::Empty> {
482        ProfileBuilder::new()
483    }
484}
485
486impl<'a> ProfileBuilder<'a, profile_state::Empty> {
487    /// Create a new builder with all fields unset
488    pub fn new() -> Self {
489        ProfileBuilder {
490            _state: PhantomData,
491            _fields: (None,),
492            _lifetime: PhantomData,
493        }
494    }
495}
496
497impl<'a, S: profile_state::State> ProfileBuilder<'a, S> {
498    /// Set the `color` field (optional)
499    pub fn color(mut self, value: impl Into<Option<profile::Color<'a>>>) -> Self {
500        self._fields.0 = value.into();
501        self
502    }
503    /// Set the `color` field to an Option value (optional)
504    pub fn maybe_color(mut self, value: Option<profile::Color<'a>>) -> Self {
505        self._fields.0 = value;
506        self
507    }
508}
509
510impl<'a, S> ProfileBuilder<'a, S>
511where
512    S: profile_state::State,
513{
514    /// Build the final struct
515    pub fn build(self) -> Profile<'a> {
516        Profile {
517            color: self._fields.0,
518            extra_data: Default::default(),
519        }
520    }
521    /// Build the final struct with custom extra_data
522    pub fn build_with_data(
523        self,
524        extra_data: BTreeMap<
525            jacquard_common::deps::smol_str::SmolStr,
526            jacquard_common::types::value::Data<'a>,
527        >,
528    ) -> Profile<'a> {
529        Profile {
530            color: self._fields.0,
531            extra_data: Some(extra_data),
532        }
533    }
534}