Skip to main content

jacquard_api/place_stream/
chat.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: place.stream.chat.defs
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8pub mod gate;
9pub mod message;
10pub mod profile;
11
12
13#[allow(unused_imports)]
14use alloc::collections::BTreeMap;
15
16#[allow(unused_imports)]
17use core::marker::PhantomData;
18
19#[allow(unused_imports)]
20use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
21use jacquard_common::types::string::{AtUri, Cid, Datetime};
22use jacquard_common::types::value::Data;
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::app_bsky::actor::ProfileViewBasic;
31use crate::place_stream::chat::profile::Profile;
32use crate::place_stream::chat;
33
34#[lexicon]
35#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
36#[serde(rename_all = "camelCase")]
37pub struct MessageView<'a> {
38    #[serde(borrow)]
39    pub author: ProfileViewBasic<'a>,
40    #[serde(skip_serializing_if = "Option::is_none")]
41    #[serde(borrow)]
42    pub chat_profile: Option<Profile<'a>>,
43    #[serde(borrow)]
44    pub cid: Cid<'a>,
45    ///If true, this message has been deleted or labeled and should be cleared from the cache
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub deleted: Option<bool>,
48    pub indexed_at: Datetime,
49    #[serde(borrow)]
50    pub record: Data<'a>,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    #[serde(borrow)]
53    pub reply_to: Option<MessageViewReplyTo<'a>>,
54    #[serde(borrow)]
55    pub uri: AtUri<'a>,
56}
57
58
59#[jacquard_derive::open_union]
60#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
61#[serde(tag = "$type", bound(deserialize = "'de: 'a"))]
62pub enum MessageViewReplyTo<'a> {
63    #[serde(rename = "place.stream.chat.defs#messageView")]
64    MessageView(Box<chat::MessageView<'a>>),
65}
66
67impl<'a> LexiconSchema for MessageView<'a> {
68    fn nsid() -> &'static str {
69        "place.stream.chat.defs"
70    }
71    fn def_name() -> &'static str {
72        "messageView"
73    }
74    fn lexicon_doc() -> LexiconDoc<'static> {
75        lexicon_doc_place_stream_chat_defs()
76    }
77    fn validate(&self) -> Result<(), ConstraintError> {
78        Ok(())
79    }
80}
81
82pub mod message_view_state {
83
84    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
85    #[allow(unused)]
86    use ::core::marker::PhantomData;
87    mod sealed {
88        pub trait Sealed {}
89    }
90    /// State trait tracking which required fields have been set
91    pub trait State: sealed::Sealed {
92        type IndexedAt;
93        type Author;
94        type Cid;
95        type Record;
96        type Uri;
97    }
98    /// Empty state - all required fields are unset
99    pub struct Empty(());
100    impl sealed::Sealed for Empty {}
101    impl State for Empty {
102        type IndexedAt = Unset;
103        type Author = Unset;
104        type Cid = Unset;
105        type Record = Unset;
106        type Uri = Unset;
107    }
108    ///State transition - sets the `indexed_at` field to Set
109    pub struct SetIndexedAt<S: State = Empty>(PhantomData<fn() -> S>);
110    impl<S: State> sealed::Sealed for SetIndexedAt<S> {}
111    impl<S: State> State for SetIndexedAt<S> {
112        type IndexedAt = Set<members::indexed_at>;
113        type Author = S::Author;
114        type Cid = S::Cid;
115        type Record = S::Record;
116        type Uri = S::Uri;
117    }
118    ///State transition - sets the `author` field to Set
119    pub struct SetAuthor<S: State = Empty>(PhantomData<fn() -> S>);
120    impl<S: State> sealed::Sealed for SetAuthor<S> {}
121    impl<S: State> State for SetAuthor<S> {
122        type IndexedAt = S::IndexedAt;
123        type Author = Set<members::author>;
124        type Cid = S::Cid;
125        type Record = S::Record;
126        type Uri = S::Uri;
127    }
128    ///State transition - sets the `cid` field to Set
129    pub struct SetCid<S: State = Empty>(PhantomData<fn() -> S>);
130    impl<S: State> sealed::Sealed for SetCid<S> {}
131    impl<S: State> State for SetCid<S> {
132        type IndexedAt = S::IndexedAt;
133        type Author = S::Author;
134        type Cid = Set<members::cid>;
135        type Record = S::Record;
136        type Uri = S::Uri;
137    }
138    ///State transition - sets the `record` field to Set
139    pub struct SetRecord<S: State = Empty>(PhantomData<fn() -> S>);
140    impl<S: State> sealed::Sealed for SetRecord<S> {}
141    impl<S: State> State for SetRecord<S> {
142        type IndexedAt = S::IndexedAt;
143        type Author = S::Author;
144        type Cid = S::Cid;
145        type Record = Set<members::record>;
146        type Uri = S::Uri;
147    }
148    ///State transition - sets the `uri` field to Set
149    pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
150    impl<S: State> sealed::Sealed for SetUri<S> {}
151    impl<S: State> State for SetUri<S> {
152        type IndexedAt = S::IndexedAt;
153        type Author = S::Author;
154        type Cid = S::Cid;
155        type Record = S::Record;
156        type Uri = Set<members::uri>;
157    }
158    /// Marker types for field names
159    #[allow(non_camel_case_types)]
160    pub mod members {
161        ///Marker type for the `indexed_at` field
162        pub struct indexed_at(());
163        ///Marker type for the `author` field
164        pub struct author(());
165        ///Marker type for the `cid` field
166        pub struct cid(());
167        ///Marker type for the `record` field
168        pub struct record(());
169        ///Marker type for the `uri` field
170        pub struct uri(());
171    }
172}
173
174/// Builder for constructing an instance of this type
175pub struct MessageViewBuilder<'a, S: message_view_state::State> {
176    _state: PhantomData<fn() -> S>,
177    _fields: (
178        Option<ProfileViewBasic<'a>>,
179        Option<Profile<'a>>,
180        Option<Cid<'a>>,
181        Option<bool>,
182        Option<Datetime>,
183        Option<Data<'a>>,
184        Option<MessageViewReplyTo<'a>>,
185        Option<AtUri<'a>>,
186    ),
187    _lifetime: PhantomData<&'a ()>,
188}
189
190impl<'a> MessageView<'a> {
191    /// Create a new builder for this type
192    pub fn new() -> MessageViewBuilder<'a, message_view_state::Empty> {
193        MessageViewBuilder::new()
194    }
195}
196
197impl<'a> MessageViewBuilder<'a, message_view_state::Empty> {
198    /// Create a new builder with all fields unset
199    pub fn new() -> Self {
200        MessageViewBuilder {
201            _state: PhantomData,
202            _fields: (None, None, None, None, None, None, None, None),
203            _lifetime: PhantomData,
204        }
205    }
206}
207
208impl<'a, S> MessageViewBuilder<'a, S>
209where
210    S: message_view_state::State,
211    S::Author: message_view_state::IsUnset,
212{
213    /// Set the `author` field (required)
214    pub fn author(
215        mut self,
216        value: impl Into<ProfileViewBasic<'a>>,
217    ) -> MessageViewBuilder<'a, message_view_state::SetAuthor<S>> {
218        self._fields.0 = Option::Some(value.into());
219        MessageViewBuilder {
220            _state: PhantomData,
221            _fields: self._fields,
222            _lifetime: PhantomData,
223        }
224    }
225}
226
227impl<'a, S: message_view_state::State> MessageViewBuilder<'a, S> {
228    /// Set the `chatProfile` field (optional)
229    pub fn chat_profile(mut self, value: impl Into<Option<Profile<'a>>>) -> Self {
230        self._fields.1 = value.into();
231        self
232    }
233    /// Set the `chatProfile` field to an Option value (optional)
234    pub fn maybe_chat_profile(mut self, value: Option<Profile<'a>>) -> Self {
235        self._fields.1 = value;
236        self
237    }
238}
239
240impl<'a, S> MessageViewBuilder<'a, S>
241where
242    S: message_view_state::State,
243    S::Cid: message_view_state::IsUnset,
244{
245    /// Set the `cid` field (required)
246    pub fn cid(
247        mut self,
248        value: impl Into<Cid<'a>>,
249    ) -> MessageViewBuilder<'a, message_view_state::SetCid<S>> {
250        self._fields.2 = Option::Some(value.into());
251        MessageViewBuilder {
252            _state: PhantomData,
253            _fields: self._fields,
254            _lifetime: PhantomData,
255        }
256    }
257}
258
259impl<'a, S: message_view_state::State> MessageViewBuilder<'a, S> {
260    /// Set the `deleted` field (optional)
261    pub fn deleted(mut self, value: impl Into<Option<bool>>) -> Self {
262        self._fields.3 = value.into();
263        self
264    }
265    /// Set the `deleted` field to an Option value (optional)
266    pub fn maybe_deleted(mut self, value: Option<bool>) -> Self {
267        self._fields.3 = value;
268        self
269    }
270}
271
272impl<'a, S> MessageViewBuilder<'a, S>
273where
274    S: message_view_state::State,
275    S::IndexedAt: message_view_state::IsUnset,
276{
277    /// Set the `indexedAt` field (required)
278    pub fn indexed_at(
279        mut self,
280        value: impl Into<Datetime>,
281    ) -> MessageViewBuilder<'a, message_view_state::SetIndexedAt<S>> {
282        self._fields.4 = Option::Some(value.into());
283        MessageViewBuilder {
284            _state: PhantomData,
285            _fields: self._fields,
286            _lifetime: PhantomData,
287        }
288    }
289}
290
291impl<'a, S> MessageViewBuilder<'a, S>
292where
293    S: message_view_state::State,
294    S::Record: message_view_state::IsUnset,
295{
296    /// Set the `record` field (required)
297    pub fn record(
298        mut self,
299        value: impl Into<Data<'a>>,
300    ) -> MessageViewBuilder<'a, message_view_state::SetRecord<S>> {
301        self._fields.5 = Option::Some(value.into());
302        MessageViewBuilder {
303            _state: PhantomData,
304            _fields: self._fields,
305            _lifetime: PhantomData,
306        }
307    }
308}
309
310impl<'a, S: message_view_state::State> MessageViewBuilder<'a, S> {
311    /// Set the `replyTo` field (optional)
312    pub fn reply_to(mut self, value: impl Into<Option<MessageViewReplyTo<'a>>>) -> Self {
313        self._fields.6 = value.into();
314        self
315    }
316    /// Set the `replyTo` field to an Option value (optional)
317    pub fn maybe_reply_to(mut self, value: Option<MessageViewReplyTo<'a>>) -> Self {
318        self._fields.6 = value;
319        self
320    }
321}
322
323impl<'a, S> MessageViewBuilder<'a, S>
324where
325    S: message_view_state::State,
326    S::Uri: message_view_state::IsUnset,
327{
328    /// Set the `uri` field (required)
329    pub fn uri(
330        mut self,
331        value: impl Into<AtUri<'a>>,
332    ) -> MessageViewBuilder<'a, message_view_state::SetUri<S>> {
333        self._fields.7 = Option::Some(value.into());
334        MessageViewBuilder {
335            _state: PhantomData,
336            _fields: self._fields,
337            _lifetime: PhantomData,
338        }
339    }
340}
341
342impl<'a, S> MessageViewBuilder<'a, S>
343where
344    S: message_view_state::State,
345    S::IndexedAt: message_view_state::IsSet,
346    S::Author: message_view_state::IsSet,
347    S::Cid: message_view_state::IsSet,
348    S::Record: message_view_state::IsSet,
349    S::Uri: message_view_state::IsSet,
350{
351    /// Build the final struct
352    pub fn build(self) -> MessageView<'a> {
353        MessageView {
354            author: self._fields.0.unwrap(),
355            chat_profile: self._fields.1,
356            cid: self._fields.2.unwrap(),
357            deleted: self._fields.3,
358            indexed_at: self._fields.4.unwrap(),
359            record: self._fields.5.unwrap(),
360            reply_to: self._fields.6,
361            uri: self._fields.7.unwrap(),
362            extra_data: Default::default(),
363        }
364    }
365    /// Build the final struct with custom extra_data
366    pub fn build_with_data(
367        self,
368        extra_data: BTreeMap<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
369    ) -> MessageView<'a> {
370        MessageView {
371            author: self._fields.0.unwrap(),
372            chat_profile: self._fields.1,
373            cid: self._fields.2.unwrap(),
374            deleted: self._fields.3,
375            indexed_at: self._fields.4.unwrap(),
376            record: self._fields.5.unwrap(),
377            reply_to: self._fields.6,
378            uri: self._fields.7.unwrap(),
379            extra_data: Some(extra_data),
380        }
381    }
382}
383
384fn lexicon_doc_place_stream_chat_defs() -> LexiconDoc<'static> {
385    #[allow(unused_imports)]
386    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
387    use jacquard_lexicon::lexicon::*;
388    use alloc::collections::BTreeMap;
389    LexiconDoc {
390        lexicon: Lexicon::Lexicon1,
391        id: CowStr::new_static("place.stream.chat.defs"),
392        defs: {
393            let mut map = BTreeMap::new();
394            map.insert(
395                SmolStr::new_static("messageView"),
396                LexUserType::Object(LexObject {
397                    required: Some(
398                        vec![
399                            SmolStr::new_static("uri"), SmolStr::new_static("cid"),
400                            SmolStr::new_static("author"), SmolStr::new_static("record"),
401                            SmolStr::new_static("indexedAt")
402                        ],
403                    ),
404                    properties: {
405                        #[allow(unused_mut)]
406                        let mut map = BTreeMap::new();
407                        map.insert(
408                            SmolStr::new_static("author"),
409                            LexObjectProperty::Ref(LexRef {
410                                r#ref: CowStr::new_static(
411                                    "app.bsky.actor.defs#profileViewBasic",
412                                ),
413                                ..Default::default()
414                            }),
415                        );
416                        map.insert(
417                            SmolStr::new_static("chatProfile"),
418                            LexObjectProperty::Ref(LexRef {
419                                r#ref: CowStr::new_static("place.stream.chat.profile"),
420                                ..Default::default()
421                            }),
422                        );
423                        map.insert(
424                            SmolStr::new_static("cid"),
425                            LexObjectProperty::String(LexString {
426                                format: Some(LexStringFormat::Cid),
427                                ..Default::default()
428                            }),
429                        );
430                        map.insert(
431                            SmolStr::new_static("deleted"),
432                            LexObjectProperty::Boolean(LexBoolean {
433                                ..Default::default()
434                            }),
435                        );
436                        map.insert(
437                            SmolStr::new_static("indexedAt"),
438                            LexObjectProperty::String(LexString {
439                                format: Some(LexStringFormat::Datetime),
440                                ..Default::default()
441                            }),
442                        );
443                        map.insert(
444                            SmolStr::new_static("record"),
445                            LexObjectProperty::Unknown(LexUnknown {
446                                ..Default::default()
447                            }),
448                        );
449                        map.insert(
450                            SmolStr::new_static("replyTo"),
451                            LexObjectProperty::Union(LexRefUnion {
452                                refs: vec![CowStr::new_static("#messageView")],
453                                ..Default::default()
454                            }),
455                        );
456                        map.insert(
457                            SmolStr::new_static("uri"),
458                            LexObjectProperty::String(LexString {
459                                format: Some(LexStringFormat::AtUri),
460                                ..Default::default()
461                            }),
462                        );
463                        map
464                    },
465                    ..Default::default()
466                }),
467            );
468            map
469        },
470        ..Default::default()
471    }
472}