1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::deps::smol_str::SmolStr;
18use jacquard_common::types::collection::{Collection, RecordError};
19use jacquard_common::types::string::{AtUri, Cid};
20use jacquard_common::types::uri::{RecordUri, UriError};
21use jacquard_common::types::value::Data;
22use jacquard_common::xrpc::XrpcResp;
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::{Deserialize, Serialize};
30#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
33#[serde(
34 rename_all = "camelCase",
35 rename = "chat.bsky.actor.declaration",
36 tag = "$type",
37 bound(deserialize = "S: Deserialize<'de> + BosStr")
38)]
39pub struct Declaration<S: BosStr = DefaultStr> {
40 #[serde(skip_serializing_if = "Option::is_none")]
42 pub allow_group_invites: Option<DeclarationAllowGroupInvites<S>>,
43 pub allow_incoming: DeclarationAllowIncoming<S>,
44 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
45 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
46}
47
48#[derive(Debug, Clone, PartialEq, Eq, Hash)]
51pub enum DeclarationAllowGroupInvites<S: BosStr = DefaultStr> {
52 All,
53 None,
54 Following,
55 Other(S),
56}
57
58impl<S: BosStr> DeclarationAllowGroupInvites<S> {
59 pub fn as_str(&self) -> &str {
60 match self {
61 Self::All => "all",
62 Self::None => "none",
63 Self::Following => "following",
64 Self::Other(s) => s.as_ref(),
65 }
66 }
67 pub fn from_value(s: S) -> Self {
69 match s.as_ref() {
70 "all" => Self::All,
71 "none" => Self::None,
72 "following" => Self::Following,
73 _ => Self::Other(s),
74 }
75 }
76}
77
78impl<S: BosStr> core::fmt::Display for DeclarationAllowGroupInvites<S> {
79 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
80 write!(f, "{}", self.as_str())
81 }
82}
83
84impl<S: BosStr> AsRef<str> for DeclarationAllowGroupInvites<S> {
85 fn as_ref(&self) -> &str {
86 self.as_str()
87 }
88}
89
90impl<S: BosStr> Serialize for DeclarationAllowGroupInvites<S> {
91 fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
92 where
93 Ser: serde::Serializer,
94 {
95 serializer.serialize_str(self.as_str())
96 }
97}
98
99impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for DeclarationAllowGroupInvites<S> {
100 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
101 where
102 D: serde::Deserializer<'de>,
103 {
104 let s = S::deserialize(deserializer)?;
105 Ok(Self::from_value(s))
106 }
107}
108
109impl<S: BosStr + Default> Default for DeclarationAllowGroupInvites<S> {
110 fn default() -> Self {
111 Self::Other(Default::default())
112 }
113}
114
115impl<S: BosStr> jacquard_common::IntoStatic for DeclarationAllowGroupInvites<S>
116where
117 S: BosStr + jacquard_common::IntoStatic,
118 S::Output: BosStr,
119{
120 type Output = DeclarationAllowGroupInvites<S::Output>;
121 fn into_static(self) -> Self::Output {
122 match self {
123 DeclarationAllowGroupInvites::All => DeclarationAllowGroupInvites::All,
124 DeclarationAllowGroupInvites::None => DeclarationAllowGroupInvites::None,
125 DeclarationAllowGroupInvites::Following => DeclarationAllowGroupInvites::Following,
126 DeclarationAllowGroupInvites::Other(v) => {
127 DeclarationAllowGroupInvites::Other(v.into_static())
128 }
129 }
130 }
131}
132
133#[derive(Debug, Clone, PartialEq, Eq, Hash)]
134pub enum DeclarationAllowIncoming<S: BosStr = DefaultStr> {
135 All,
136 None,
137 Following,
138 Other(S),
139}
140
141impl<S: BosStr> DeclarationAllowIncoming<S> {
142 pub fn as_str(&self) -> &str {
143 match self {
144 Self::All => "all",
145 Self::None => "none",
146 Self::Following => "following",
147 Self::Other(s) => s.as_ref(),
148 }
149 }
150 pub fn from_value(s: S) -> Self {
152 match s.as_ref() {
153 "all" => Self::All,
154 "none" => Self::None,
155 "following" => Self::Following,
156 _ => Self::Other(s),
157 }
158 }
159}
160
161impl<S: BosStr> core::fmt::Display for DeclarationAllowIncoming<S> {
162 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
163 write!(f, "{}", self.as_str())
164 }
165}
166
167impl<S: BosStr> AsRef<str> for DeclarationAllowIncoming<S> {
168 fn as_ref(&self) -> &str {
169 self.as_str()
170 }
171}
172
173impl<S: BosStr> Serialize for DeclarationAllowIncoming<S> {
174 fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
175 where
176 Ser: serde::Serializer,
177 {
178 serializer.serialize_str(self.as_str())
179 }
180}
181
182impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for DeclarationAllowIncoming<S> {
183 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
184 where
185 D: serde::Deserializer<'de>,
186 {
187 let s = S::deserialize(deserializer)?;
188 Ok(Self::from_value(s))
189 }
190}
191
192impl<S: BosStr + Default> Default for DeclarationAllowIncoming<S> {
193 fn default() -> Self {
194 Self::Other(Default::default())
195 }
196}
197
198impl<S: BosStr> jacquard_common::IntoStatic for DeclarationAllowIncoming<S>
199where
200 S: BosStr + jacquard_common::IntoStatic,
201 S::Output: BosStr,
202{
203 type Output = DeclarationAllowIncoming<S::Output>;
204 fn into_static(self) -> Self::Output {
205 match self {
206 DeclarationAllowIncoming::All => DeclarationAllowIncoming::All,
207 DeclarationAllowIncoming::None => DeclarationAllowIncoming::None,
208 DeclarationAllowIncoming::Following => DeclarationAllowIncoming::Following,
209 DeclarationAllowIncoming::Other(v) => DeclarationAllowIncoming::Other(v.into_static()),
210 }
211 }
212}
213
214#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
217#[serde(rename_all = "camelCase")]
218pub struct DeclarationGetRecordOutput<S: BosStr = DefaultStr> {
219 #[serde(skip_serializing_if = "Option::is_none")]
220 pub cid: Option<Cid<S>>,
221 pub uri: AtUri<S>,
222 pub value: Declaration<S>,
223}
224
225impl<S: BosStr> Declaration<S> {
226 pub fn uri(uri: S) -> Result<RecordUri<S, DeclarationRecord>, UriError> {
227 RecordUri::try_from_uri(AtUri::new(uri)?)
228 }
229}
230
231#[derive(Debug, Serialize, Deserialize)]
234pub struct DeclarationRecord;
235impl XrpcResp for DeclarationRecord {
236 const NSID: &'static str = "chat.bsky.actor.declaration";
237 const ENCODING: &'static str = "application/json";
238 type Output<S: BosStr> = DeclarationGetRecordOutput<S>;
239 type Err = RecordError;
240}
241
242impl<S: BosStr> From<DeclarationGetRecordOutput<S>> for Declaration<S> {
243 fn from(output: DeclarationGetRecordOutput<S>) -> Self {
244 output.value
245 }
246}
247
248impl<S: BosStr> Collection for Declaration<S> {
249 const NSID: &'static str = "chat.bsky.actor.declaration";
250 type Record = DeclarationRecord;
251}
252
253impl Collection for DeclarationRecord {
254 const NSID: &'static str = "chat.bsky.actor.declaration";
255 type Record = DeclarationRecord;
256}
257
258impl<S: BosStr> LexiconSchema for Declaration<S> {
259 fn nsid() -> &'static str {
260 "chat.bsky.actor.declaration"
261 }
262 fn def_name() -> &'static str {
263 "main"
264 }
265 fn lexicon_doc() -> LexiconDoc<'static> {
266 lexicon_doc_chat_bsky_actor_declaration()
267 }
268 fn validate(&self) -> Result<(), ConstraintError> {
269 Ok(())
270 }
271}
272
273pub mod declaration_state {
274
275 pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
276 #[allow(unused)]
277 use ::core::marker::PhantomData;
278 mod sealed {
279 pub trait Sealed {}
280 }
281 pub trait State: sealed::Sealed {
283 type AllowIncoming;
284 }
285 pub struct Empty(());
287 impl sealed::Sealed for Empty {}
288 impl State for Empty {
289 type AllowIncoming = Unset;
290 }
291 pub struct SetAllowIncoming<St: State = Empty>(PhantomData<fn() -> St>);
293 impl<St: State> sealed::Sealed for SetAllowIncoming<St> {}
294 impl<St: State> State for SetAllowIncoming<St> {
295 type AllowIncoming = Set<members::allow_incoming>;
296 }
297 #[allow(non_camel_case_types)]
299 pub mod members {
300 pub struct allow_incoming(());
302 }
303}
304
305pub struct DeclarationBuilder<St: declaration_state::State, S: BosStr = DefaultStr> {
307 _state: PhantomData<fn() -> St>,
308 _fields: (
309 Option<DeclarationAllowGroupInvites<S>>,
310 Option<DeclarationAllowIncoming<S>>,
311 ),
312 _type: PhantomData<fn() -> S>,
313}
314
315impl Declaration<DefaultStr> {
316 pub fn new() -> DeclarationBuilder<declaration_state::Empty, DefaultStr> {
318 DeclarationBuilder::new()
319 }
320}
321
322impl<S: BosStr> Declaration<S> {
323 pub fn builder() -> DeclarationBuilder<declaration_state::Empty, S> {
325 DeclarationBuilder::builder()
326 }
327}
328
329impl DeclarationBuilder<declaration_state::Empty, DefaultStr> {
330 pub fn new() -> Self {
332 DeclarationBuilder {
333 _state: PhantomData,
334 _fields: (None, None),
335 _type: PhantomData,
336 }
337 }
338}
339
340impl<S: BosStr> DeclarationBuilder<declaration_state::Empty, S> {
341 pub fn builder() -> Self {
343 DeclarationBuilder {
344 _state: PhantomData,
345 _fields: (None, None),
346 _type: PhantomData,
347 }
348 }
349}
350
351impl<St: declaration_state::State, S: BosStr> DeclarationBuilder<St, S> {
352 pub fn allow_group_invites(
354 mut self,
355 value: impl Into<Option<DeclarationAllowGroupInvites<S>>>,
356 ) -> Self {
357 self._fields.0 = value.into();
358 self
359 }
360 pub fn maybe_allow_group_invites(
362 mut self,
363 value: Option<DeclarationAllowGroupInvites<S>>,
364 ) -> Self {
365 self._fields.0 = value;
366 self
367 }
368}
369
370impl<St, S: BosStr> DeclarationBuilder<St, S>
371where
372 St: declaration_state::State,
373 St::AllowIncoming: declaration_state::IsUnset,
374{
375 pub fn allow_incoming(
377 mut self,
378 value: impl Into<DeclarationAllowIncoming<S>>,
379 ) -> DeclarationBuilder<declaration_state::SetAllowIncoming<St>, S> {
380 self._fields.1 = Option::Some(value.into());
381 DeclarationBuilder {
382 _state: PhantomData,
383 _fields: self._fields,
384 _type: PhantomData,
385 }
386 }
387}
388
389impl<St, S: BosStr> DeclarationBuilder<St, S>
390where
391 St: declaration_state::State,
392 St::AllowIncoming: declaration_state::IsSet,
393{
394 pub fn build(self) -> Declaration<S> {
396 Declaration {
397 allow_group_invites: self._fields.0,
398 allow_incoming: self._fields.1.unwrap(),
399 extra_data: Default::default(),
400 }
401 }
402 pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Declaration<S> {
404 Declaration {
405 allow_group_invites: self._fields.0,
406 allow_incoming: self._fields.1.unwrap(),
407 extra_data: Some(extra_data),
408 }
409 }
410}
411
412fn lexicon_doc_chat_bsky_actor_declaration() -> LexiconDoc<'static> {
413 use alloc::collections::BTreeMap;
414 #[allow(unused_imports)]
415 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
416 use jacquard_lexicon::lexicon::*;
417 LexiconDoc {
418 lexicon: Lexicon::Lexicon1,
419 id: CowStr::new_static("chat.bsky.actor.declaration"),
420 defs: {
421 let mut map = BTreeMap::new();
422 map.insert(
423 SmolStr::new_static("main"),
424 LexUserType::Record(LexRecord {
425 description: Some(
426 CowStr::new_static("A declaration of a Bluesky chat account."),
427 ),
428 key: Some(CowStr::new_static("literal:self")),
429 record: LexRecordRecord::Object(LexObject {
430 required: Some(vec![SmolStr::new_static("allowIncoming")]),
431 properties: {
432 #[allow(unused_mut)]
433 let mut map = BTreeMap::new();
434 map.insert(
435 SmolStr::new_static("allowGroupInvites"),
436 LexObjectProperty::String(LexString {
437 description: Some(
438 CowStr::new_static(
439 "Declaration about group chat invitation preferences for the record owner.",
440 ),
441 ),
442 ..Default::default()
443 }),
444 );
445 map.insert(
446 SmolStr::new_static("allowIncoming"),
447 LexObjectProperty::String(LexString {
448 ..Default::default()
449 }),
450 );
451 map
452 },
453 ..Default::default()
454 }),
455 ..Default::default()
456 }),
457 );
458 map
459 },
460 ..Default::default()
461 }
462}