Skip to main content

jacquard_api/chat_bsky/actor/
declaration.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: chat.bsky.actor.declaration
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};
28/// A declaration of a Bluesky chat account.
29
30#[lexicon]
31#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
32#[serde(rename_all = "camelCase", rename = "chat.bsky.actor.declaration", tag = "$type")]
33pub struct Declaration<'a> {
34    #[serde(borrow)]
35    pub allow_incoming: DeclarationAllowIncoming<'a>,
36}
37
38
39#[derive(Debug, Clone, PartialEq, Eq, Hash)]
40pub enum DeclarationAllowIncoming<'a> {
41    All,
42    None,
43    Following,
44    Other(CowStr<'a>),
45}
46
47impl<'a> DeclarationAllowIncoming<'a> {
48    pub fn as_str(&self) -> &str {
49        match self {
50            Self::All => "all",
51            Self::None => "none",
52            Self::Following => "following",
53            Self::Other(s) => s.as_ref(),
54        }
55    }
56}
57
58impl<'a> From<&'a str> for DeclarationAllowIncoming<'a> {
59    fn from(s: &'a str) -> Self {
60        match s {
61            "all" => Self::All,
62            "none" => Self::None,
63            "following" => Self::Following,
64            _ => Self::Other(CowStr::from(s)),
65        }
66    }
67}
68
69impl<'a> From<String> for DeclarationAllowIncoming<'a> {
70    fn from(s: String) -> Self {
71        match s.as_str() {
72            "all" => Self::All,
73            "none" => Self::None,
74            "following" => Self::Following,
75            _ => Self::Other(CowStr::from(s)),
76        }
77    }
78}
79
80impl<'a> core::fmt::Display for DeclarationAllowIncoming<'a> {
81    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
82        write!(f, "{}", self.as_str())
83    }
84}
85
86impl<'a> AsRef<str> for DeclarationAllowIncoming<'a> {
87    fn as_ref(&self) -> &str {
88        self.as_str()
89    }
90}
91
92impl<'a> serde::Serialize for DeclarationAllowIncoming<'a> {
93    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
94    where
95        S: serde::Serializer,
96    {
97        serializer.serialize_str(self.as_str())
98    }
99}
100
101impl<'de, 'a> serde::Deserialize<'de> for DeclarationAllowIncoming<'a>
102where
103    'de: 'a,
104{
105    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
106    where
107        D: serde::Deserializer<'de>,
108    {
109        let s = <&'de str>::deserialize(deserializer)?;
110        Ok(Self::from(s))
111    }
112}
113
114impl<'a> Default for DeclarationAllowIncoming<'a> {
115    fn default() -> Self {
116        Self::Other(Default::default())
117    }
118}
119
120impl jacquard_common::IntoStatic for DeclarationAllowIncoming<'_> {
121    type Output = DeclarationAllowIncoming<'static>;
122    fn into_static(self) -> Self::Output {
123        match self {
124            DeclarationAllowIncoming::All => DeclarationAllowIncoming::All,
125            DeclarationAllowIncoming::None => DeclarationAllowIncoming::None,
126            DeclarationAllowIncoming::Following => DeclarationAllowIncoming::Following,
127            DeclarationAllowIncoming::Other(v) => {
128                DeclarationAllowIncoming::Other(v.into_static())
129            }
130        }
131    }
132}
133
134/// Typed wrapper for GetRecord response with this collection's record type.
135
136#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
137#[serde(rename_all = "camelCase")]
138pub struct DeclarationGetRecordOutput<'a> {
139    #[serde(skip_serializing_if = "Option::is_none")]
140    #[serde(borrow)]
141    pub cid: Option<Cid<'a>>,
142    #[serde(borrow)]
143    pub uri: AtUri<'a>,
144    #[serde(borrow)]
145    pub value: Declaration<'a>,
146}
147
148impl<'a> Declaration<'a> {
149    pub fn uri(
150        uri: impl Into<CowStr<'a>>,
151    ) -> Result<RecordUri<'a, DeclarationRecord>, UriError> {
152        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
153    }
154}
155
156/// Marker type for deserializing records from this collection.
157
158#[derive(Debug, Serialize, Deserialize)]
159pub struct DeclarationRecord;
160impl XrpcResp for DeclarationRecord {
161    const NSID: &'static str = "chat.bsky.actor.declaration";
162    const ENCODING: &'static str = "application/json";
163    type Output<'de> = DeclarationGetRecordOutput<'de>;
164    type Err<'de> = RecordError<'de>;
165}
166
167impl From<DeclarationGetRecordOutput<'_>> for Declaration<'_> {
168    fn from(output: DeclarationGetRecordOutput<'_>) -> Self {
169        use jacquard_common::IntoStatic;
170        output.value.into_static()
171    }
172}
173
174impl Collection for Declaration<'_> {
175    const NSID: &'static str = "chat.bsky.actor.declaration";
176    type Record = DeclarationRecord;
177}
178
179impl Collection for DeclarationRecord {
180    const NSID: &'static str = "chat.bsky.actor.declaration";
181    type Record = DeclarationRecord;
182}
183
184impl<'a> LexiconSchema for Declaration<'a> {
185    fn nsid() -> &'static str {
186        "chat.bsky.actor.declaration"
187    }
188    fn def_name() -> &'static str {
189        "main"
190    }
191    fn lexicon_doc() -> LexiconDoc<'static> {
192        lexicon_doc_chat_bsky_actor_declaration()
193    }
194    fn validate(&self) -> Result<(), ConstraintError> {
195        Ok(())
196    }
197}
198
199pub mod declaration_state {
200
201    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
202    #[allow(unused)]
203    use ::core::marker::PhantomData;
204    mod sealed {
205        pub trait Sealed {}
206    }
207    /// State trait tracking which required fields have been set
208    pub trait State: sealed::Sealed {
209        type AllowIncoming;
210    }
211    /// Empty state - all required fields are unset
212    pub struct Empty(());
213    impl sealed::Sealed for Empty {}
214    impl State for Empty {
215        type AllowIncoming = Unset;
216    }
217    ///State transition - sets the `allow_incoming` field to Set
218    pub struct SetAllowIncoming<S: State = Empty>(PhantomData<fn() -> S>);
219    impl<S: State> sealed::Sealed for SetAllowIncoming<S> {}
220    impl<S: State> State for SetAllowIncoming<S> {
221        type AllowIncoming = Set<members::allow_incoming>;
222    }
223    /// Marker types for field names
224    #[allow(non_camel_case_types)]
225    pub mod members {
226        ///Marker type for the `allow_incoming` field
227        pub struct allow_incoming(());
228    }
229}
230
231/// Builder for constructing an instance of this type
232pub struct DeclarationBuilder<'a, S: declaration_state::State> {
233    _state: PhantomData<fn() -> S>,
234    _fields: (Option<DeclarationAllowIncoming<'a>>,),
235    _lifetime: PhantomData<&'a ()>,
236}
237
238impl<'a> Declaration<'a> {
239    /// Create a new builder for this type
240    pub fn new() -> DeclarationBuilder<'a, declaration_state::Empty> {
241        DeclarationBuilder::new()
242    }
243}
244
245impl<'a> DeclarationBuilder<'a, declaration_state::Empty> {
246    /// Create a new builder with all fields unset
247    pub fn new() -> Self {
248        DeclarationBuilder {
249            _state: PhantomData,
250            _fields: (None,),
251            _lifetime: PhantomData,
252        }
253    }
254}
255
256impl<'a, S> DeclarationBuilder<'a, S>
257where
258    S: declaration_state::State,
259    S::AllowIncoming: declaration_state::IsUnset,
260{
261    /// Set the `allowIncoming` field (required)
262    pub fn allow_incoming(
263        mut self,
264        value: impl Into<DeclarationAllowIncoming<'a>>,
265    ) -> DeclarationBuilder<'a, declaration_state::SetAllowIncoming<S>> {
266        self._fields.0 = Option::Some(value.into());
267        DeclarationBuilder {
268            _state: PhantomData,
269            _fields: self._fields,
270            _lifetime: PhantomData,
271        }
272    }
273}
274
275impl<'a, S> DeclarationBuilder<'a, S>
276where
277    S: declaration_state::State,
278    S::AllowIncoming: declaration_state::IsSet,
279{
280    /// Build the final struct
281    pub fn build(self) -> Declaration<'a> {
282        Declaration {
283            allow_incoming: self._fields.0.unwrap(),
284            extra_data: Default::default(),
285        }
286    }
287    /// Build the final struct with custom extra_data
288    pub fn build_with_data(
289        self,
290        extra_data: BTreeMap<
291            jacquard_common::deps::smol_str::SmolStr,
292            jacquard_common::types::value::Data<'a>,
293        >,
294    ) -> Declaration<'a> {
295        Declaration {
296            allow_incoming: self._fields.0.unwrap(),
297            extra_data: Some(extra_data),
298        }
299    }
300}
301
302fn lexicon_doc_chat_bsky_actor_declaration() -> LexiconDoc<'static> {
303    #[allow(unused_imports)]
304    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
305    use jacquard_lexicon::lexicon::*;
306    use alloc::collections::BTreeMap;
307    LexiconDoc {
308        lexicon: Lexicon::Lexicon1,
309        id: CowStr::new_static("chat.bsky.actor.declaration"),
310        defs: {
311            let mut map = BTreeMap::new();
312            map.insert(
313                SmolStr::new_static("main"),
314                LexUserType::Record(LexRecord {
315                    description: Some(
316                        CowStr::new_static("A declaration of a Bluesky chat account."),
317                    ),
318                    key: Some(CowStr::new_static("literal:self")),
319                    record: LexRecordRecord::Object(LexObject {
320                        required: Some(vec![SmolStr::new_static("allowIncoming")]),
321                        properties: {
322                            #[allow(unused_mut)]
323                            let mut map = BTreeMap::new();
324                            map.insert(
325                                SmolStr::new_static("allowIncoming"),
326                                LexObjectProperty::String(LexString {
327                                    ..Default::default()
328                                }),
329                            );
330                            map
331                        },
332                        ..Default::default()
333                    }),
334                    ..Default::default()
335                }),
336            );
337            map
338        },
339        ..Default::default()
340    }
341}