Skip to main content

jacquard_api/chat_bsky/
notification.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: chat.bsky.notification.defs
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8//! Generated bindings for the `chat.bsky.notification` Lexicon namespace/module.
9pub mod get_preferences;
10pub mod put_preferences;
11
12#[allow(unused_imports)]
13use alloc::collections::BTreeMap;
14
15#[allow(unused_imports)]
16use core::marker::PhantomData;
17use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
18
19#[allow(unused_imports)]
20use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
21use jacquard_common::deps::smol_str::SmolStr;
22use jacquard_common::types::value::Data;
23use jacquard_derive::IntoStatic;
24use jacquard_lexicon::lexicon::LexiconDoc;
25use jacquard_lexicon::schema::LexiconSchema;
26
27use crate::chat_bsky::notification;
28#[allow(unused_imports)]
29use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
30use serde::{Deserialize, Serialize};
31
32#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
33#[serde(
34    rename_all = "camelCase",
35    bound(deserialize = "S: Deserialize<'de> + BosStr")
36)]
37pub struct ChatPreference<S: BosStr = DefaultStr> {
38    pub include: ChatPreferenceInclude<S>,
39    pub push: bool,
40    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
41    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
42}
43
44#[derive(Debug, Clone, PartialEq, Eq, Hash)]
45pub enum ChatPreferenceInclude<S: BosStr = DefaultStr> {
46    All,
47    Follows,
48    Other(S),
49}
50
51impl<S: BosStr> ChatPreferenceInclude<S> {
52    pub fn as_str(&self) -> &str {
53        match self {
54            Self::All => "all",
55            Self::Follows => "follows",
56            Self::Other(s) => s.as_ref(),
57        }
58    }
59    /// Construct from a string-like value, matching known values.
60    pub fn from_value(s: S) -> Self {
61        match s.as_ref() {
62            "all" => Self::All,
63            "follows" => Self::Follows,
64            _ => Self::Other(s),
65        }
66    }
67}
68
69impl<S: BosStr> core::fmt::Display for ChatPreferenceInclude<S> {
70    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71        write!(f, "{}", self.as_str())
72    }
73}
74
75impl<S: BosStr> AsRef<str> for ChatPreferenceInclude<S> {
76    fn as_ref(&self) -> &str {
77        self.as_str()
78    }
79}
80
81impl<S: BosStr> Serialize for ChatPreferenceInclude<S> {
82    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
83    where
84        Ser: serde::Serializer,
85    {
86        serializer.serialize_str(self.as_str())
87    }
88}
89
90impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for ChatPreferenceInclude<S> {
91    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
92    where
93        D: serde::Deserializer<'de>,
94    {
95        let s = S::deserialize(deserializer)?;
96        Ok(Self::from_value(s))
97    }
98}
99
100impl<S: BosStr + Default> Default for ChatPreferenceInclude<S> {
101    fn default() -> Self {
102        Self::Other(Default::default())
103    }
104}
105
106impl<S: BosStr> jacquard_common::IntoStatic for ChatPreferenceInclude<S>
107where
108    S: BosStr + jacquard_common::IntoStatic,
109    S::Output: BosStr,
110{
111    type Output = ChatPreferenceInclude<S::Output>;
112    fn into_static(self) -> Self::Output {
113        match self {
114            ChatPreferenceInclude::All => ChatPreferenceInclude::All,
115            ChatPreferenceInclude::Follows => ChatPreferenceInclude::Follows,
116            ChatPreferenceInclude::Other(v) => ChatPreferenceInclude::Other(v.into_static()),
117        }
118    }
119}
120
121#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
122#[serde(
123    rename_all = "camelCase",
124    bound(deserialize = "S: Deserialize<'de> + BosStr")
125)]
126pub struct Preferences<S: BosStr = DefaultStr> {
127    pub chat: notification::ChatPreference<S>,
128    pub chat_request: notification::ChatPreference<S>,
129    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
130    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
131}
132
133impl<S: BosStr> LexiconSchema for ChatPreference<S> {
134    fn nsid() -> &'static str {
135        "chat.bsky.notification.defs"
136    }
137    fn def_name() -> &'static str {
138        "chatPreference"
139    }
140    fn lexicon_doc() -> LexiconDoc<'static> {
141        lexicon_doc_chat_bsky_notification_defs()
142    }
143    fn validate(&self) -> Result<(), ConstraintError> {
144        Ok(())
145    }
146}
147
148impl<S: BosStr> LexiconSchema for Preferences<S> {
149    fn nsid() -> &'static str {
150        "chat.bsky.notification.defs"
151    }
152    fn def_name() -> &'static str {
153        "preferences"
154    }
155    fn lexicon_doc() -> LexiconDoc<'static> {
156        lexicon_doc_chat_bsky_notification_defs()
157    }
158    fn validate(&self) -> Result<(), ConstraintError> {
159        Ok(())
160    }
161}
162
163pub mod chat_preference_state {
164
165    pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
166    #[allow(unused)]
167    use ::core::marker::PhantomData;
168    mod sealed {
169        pub trait Sealed {}
170    }
171    /// State trait tracking which required fields have been set
172    pub trait State: sealed::Sealed {
173        type Include;
174        type Push;
175    }
176    /// Empty state - all required fields are unset
177    pub struct Empty(());
178    impl sealed::Sealed for Empty {}
179    impl State for Empty {
180        type Include = Unset;
181        type Push = Unset;
182    }
183    ///State transition - sets the `include` field to Set
184    pub struct SetInclude<St: State = Empty>(PhantomData<fn() -> St>);
185    impl<St: State> sealed::Sealed for SetInclude<St> {}
186    impl<St: State> State for SetInclude<St> {
187        type Include = Set<members::include>;
188        type Push = St::Push;
189    }
190    ///State transition - sets the `push` field to Set
191    pub struct SetPush<St: State = Empty>(PhantomData<fn() -> St>);
192    impl<St: State> sealed::Sealed for SetPush<St> {}
193    impl<St: State> State for SetPush<St> {
194        type Include = St::Include;
195        type Push = Set<members::push>;
196    }
197    /// Marker types for field names
198    #[allow(non_camel_case_types)]
199    pub mod members {
200        ///Marker type for the `include` field
201        pub struct include(());
202        ///Marker type for the `push` field
203        pub struct push(());
204    }
205}
206
207/// Builder for constructing an instance of this type.
208pub struct ChatPreferenceBuilder<St: chat_preference_state::State, S: BosStr = DefaultStr> {
209    _state: PhantomData<fn() -> St>,
210    _fields: (Option<ChatPreferenceInclude<S>>, Option<bool>),
211    _type: PhantomData<fn() -> S>,
212}
213
214impl ChatPreference<DefaultStr> {
215    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
216    pub fn new() -> ChatPreferenceBuilder<chat_preference_state::Empty, DefaultStr> {
217        ChatPreferenceBuilder::new()
218    }
219}
220
221impl<S: BosStr> ChatPreference<S> {
222    /// Create a new builder for this type
223    pub fn builder() -> ChatPreferenceBuilder<chat_preference_state::Empty, S> {
224        ChatPreferenceBuilder::builder()
225    }
226}
227
228impl ChatPreferenceBuilder<chat_preference_state::Empty, DefaultStr> {
229    /// Create a new builder with all fields unset, using the default string type, if needed
230    pub fn new() -> Self {
231        ChatPreferenceBuilder {
232            _state: PhantomData,
233            _fields: (None, None),
234            _type: PhantomData,
235        }
236    }
237}
238
239impl<S: BosStr> ChatPreferenceBuilder<chat_preference_state::Empty, S> {
240    /// Create a new builder with all fields unset
241    pub fn builder() -> Self {
242        ChatPreferenceBuilder {
243            _state: PhantomData,
244            _fields: (None, None),
245            _type: PhantomData,
246        }
247    }
248}
249
250impl<St, S: BosStr> ChatPreferenceBuilder<St, S>
251where
252    St: chat_preference_state::State,
253    St::Include: chat_preference_state::IsUnset,
254{
255    /// Set the `include` field (required)
256    pub fn include(
257        mut self,
258        value: impl Into<ChatPreferenceInclude<S>>,
259    ) -> ChatPreferenceBuilder<chat_preference_state::SetInclude<St>, S> {
260        self._fields.0 = Option::Some(value.into());
261        ChatPreferenceBuilder {
262            _state: PhantomData,
263            _fields: self._fields,
264            _type: PhantomData,
265        }
266    }
267}
268
269impl<St, S: BosStr> ChatPreferenceBuilder<St, S>
270where
271    St: chat_preference_state::State,
272    St::Push: chat_preference_state::IsUnset,
273{
274    /// Set the `push` field (required)
275    pub fn push(
276        mut self,
277        value: impl Into<bool>,
278    ) -> ChatPreferenceBuilder<chat_preference_state::SetPush<St>, S> {
279        self._fields.1 = Option::Some(value.into());
280        ChatPreferenceBuilder {
281            _state: PhantomData,
282            _fields: self._fields,
283            _type: PhantomData,
284        }
285    }
286}
287
288impl<St, S: BosStr> ChatPreferenceBuilder<St, S>
289where
290    St: chat_preference_state::State,
291    St::Include: chat_preference_state::IsSet,
292    St::Push: chat_preference_state::IsSet,
293{
294    /// Build the final struct.
295    pub fn build(self) -> ChatPreference<S> {
296        ChatPreference {
297            include: self._fields.0.unwrap(),
298            push: self._fields.1.unwrap(),
299            extra_data: Default::default(),
300        }
301    }
302    /// Build the final struct with custom extra_data.
303    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> ChatPreference<S> {
304        ChatPreference {
305            include: self._fields.0.unwrap(),
306            push: self._fields.1.unwrap(),
307            extra_data: Some(extra_data),
308        }
309    }
310}
311
312fn lexicon_doc_chat_bsky_notification_defs() -> LexiconDoc<'static> {
313    use alloc::collections::BTreeMap;
314    #[allow(unused_imports)]
315    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
316    use jacquard_lexicon::lexicon::*;
317    LexiconDoc {
318        lexicon: Lexicon::Lexicon1,
319        id: CowStr::new_static("chat.bsky.notification.defs"),
320        defs: {
321            let mut map = BTreeMap::new();
322            map.insert(
323                SmolStr::new_static("chatPreference"),
324                LexUserType::Object(LexObject {
325                    required: Some(vec![
326                        SmolStr::new_static("include"),
327                        SmolStr::new_static("push"),
328                    ]),
329                    properties: {
330                        #[allow(unused_mut)]
331                        let mut map = BTreeMap::new();
332                        map.insert(
333                            SmolStr::new_static("include"),
334                            LexObjectProperty::String(LexString {
335                                ..Default::default()
336                            }),
337                        );
338                        map.insert(
339                            SmolStr::new_static("push"),
340                            LexObjectProperty::Boolean(LexBoolean {
341                                ..Default::default()
342                            }),
343                        );
344                        map
345                    },
346                    ..Default::default()
347                }),
348            );
349            map.insert(
350                SmolStr::new_static("preferences"),
351                LexUserType::Object(LexObject {
352                    required: Some(vec![
353                        SmolStr::new_static("chat"),
354                        SmolStr::new_static("chatRequest"),
355                    ]),
356                    properties: {
357                        #[allow(unused_mut)]
358                        let mut map = BTreeMap::new();
359                        map.insert(
360                            SmolStr::new_static("chat"),
361                            LexObjectProperty::Ref(LexRef {
362                                r#ref: CowStr::new_static("#chatPreference"),
363                                ..Default::default()
364                            }),
365                        );
366                        map.insert(
367                            SmolStr::new_static("chatRequest"),
368                            LexObjectProperty::Ref(LexRef {
369                                r#ref: CowStr::new_static("#chatPreference"),
370                                ..Default::default()
371                            }),
372                        );
373                        map
374                    },
375                    ..Default::default()
376                }),
377            );
378            map
379        },
380        ..Default::default()
381    }
382}
383
384pub mod preferences_state {
385
386    pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
387    #[allow(unused)]
388    use ::core::marker::PhantomData;
389    mod sealed {
390        pub trait Sealed {}
391    }
392    /// State trait tracking which required fields have been set
393    pub trait State: sealed::Sealed {
394        type Chat;
395        type ChatRequest;
396    }
397    /// Empty state - all required fields are unset
398    pub struct Empty(());
399    impl sealed::Sealed for Empty {}
400    impl State for Empty {
401        type Chat = Unset;
402        type ChatRequest = Unset;
403    }
404    ///State transition - sets the `chat` field to Set
405    pub struct SetChat<St: State = Empty>(PhantomData<fn() -> St>);
406    impl<St: State> sealed::Sealed for SetChat<St> {}
407    impl<St: State> State for SetChat<St> {
408        type Chat = Set<members::chat>;
409        type ChatRequest = St::ChatRequest;
410    }
411    ///State transition - sets the `chat_request` field to Set
412    pub struct SetChatRequest<St: State = Empty>(PhantomData<fn() -> St>);
413    impl<St: State> sealed::Sealed for SetChatRequest<St> {}
414    impl<St: State> State for SetChatRequest<St> {
415        type Chat = St::Chat;
416        type ChatRequest = Set<members::chat_request>;
417    }
418    /// Marker types for field names
419    #[allow(non_camel_case_types)]
420    pub mod members {
421        ///Marker type for the `chat` field
422        pub struct chat(());
423        ///Marker type for the `chat_request` field
424        pub struct chat_request(());
425    }
426}
427
428/// Builder for constructing an instance of this type.
429pub struct PreferencesBuilder<St: preferences_state::State, S: BosStr = DefaultStr> {
430    _state: PhantomData<fn() -> St>,
431    _fields: (
432        Option<notification::ChatPreference<S>>,
433        Option<notification::ChatPreference<S>>,
434    ),
435    _type: PhantomData<fn() -> S>,
436}
437
438impl Preferences<DefaultStr> {
439    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
440    pub fn new() -> PreferencesBuilder<preferences_state::Empty, DefaultStr> {
441        PreferencesBuilder::new()
442    }
443}
444
445impl<S: BosStr> Preferences<S> {
446    /// Create a new builder for this type
447    pub fn builder() -> PreferencesBuilder<preferences_state::Empty, S> {
448        PreferencesBuilder::builder()
449    }
450}
451
452impl PreferencesBuilder<preferences_state::Empty, DefaultStr> {
453    /// Create a new builder with all fields unset, using the default string type, if needed
454    pub fn new() -> Self {
455        PreferencesBuilder {
456            _state: PhantomData,
457            _fields: (None, None),
458            _type: PhantomData,
459        }
460    }
461}
462
463impl<S: BosStr> PreferencesBuilder<preferences_state::Empty, S> {
464    /// Create a new builder with all fields unset
465    pub fn builder() -> Self {
466        PreferencesBuilder {
467            _state: PhantomData,
468            _fields: (None, None),
469            _type: PhantomData,
470        }
471    }
472}
473
474impl<St, S: BosStr> PreferencesBuilder<St, S>
475where
476    St: preferences_state::State,
477    St::Chat: preferences_state::IsUnset,
478{
479    /// Set the `chat` field (required)
480    pub fn chat(
481        mut self,
482        value: impl Into<notification::ChatPreference<S>>,
483    ) -> PreferencesBuilder<preferences_state::SetChat<St>, S> {
484        self._fields.0 = Option::Some(value.into());
485        PreferencesBuilder {
486            _state: PhantomData,
487            _fields: self._fields,
488            _type: PhantomData,
489        }
490    }
491}
492
493impl<St, S: BosStr> PreferencesBuilder<St, S>
494where
495    St: preferences_state::State,
496    St::ChatRequest: preferences_state::IsUnset,
497{
498    /// Set the `chatRequest` field (required)
499    pub fn chat_request(
500        mut self,
501        value: impl Into<notification::ChatPreference<S>>,
502    ) -> PreferencesBuilder<preferences_state::SetChatRequest<St>, S> {
503        self._fields.1 = Option::Some(value.into());
504        PreferencesBuilder {
505            _state: PhantomData,
506            _fields: self._fields,
507            _type: PhantomData,
508        }
509    }
510}
511
512impl<St, S: BosStr> PreferencesBuilder<St, S>
513where
514    St: preferences_state::State,
515    St::Chat: preferences_state::IsSet,
516    St::ChatRequest: preferences_state::IsSet,
517{
518    /// Build the final struct.
519    pub fn build(self) -> Preferences<S> {
520        Preferences {
521            chat: self._fields.0.unwrap(),
522            chat_request: self._fields.1.unwrap(),
523            extra_data: Default::default(),
524        }
525    }
526    /// Build the final struct with custom extra_data.
527    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Preferences<S> {
528        Preferences {
529            chat: self._fields.0.unwrap(),
530            chat_request: self._fields.1.unwrap(),
531            extra_data: Some(extra_data),
532        }
533    }
534}