1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::{CowStr, BosStr, 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::{Serialize, Deserialize};
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>
100for DeclarationAllowGroupInvites<S> {
101 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
102 where
103 D: serde::Deserializer<'de>,
104 {
105 let s = S::deserialize(deserializer)?;
106 Ok(Self::from_value(s))
107 }
108}
109
110impl<S: BosStr + Default> Default for DeclarationAllowGroupInvites<S> {
111 fn default() -> Self {
112 Self::Other(Default::default())
113 }
114}
115
116impl<S: BosStr> jacquard_common::IntoStatic for DeclarationAllowGroupInvites<S>
117where
118 S: BosStr + jacquard_common::IntoStatic,
119 S::Output: BosStr,
120{
121 type Output = DeclarationAllowGroupInvites<S::Output>;
122 fn into_static(self) -> Self::Output {
123 match self {
124 DeclarationAllowGroupInvites::All => DeclarationAllowGroupInvites::All,
125 DeclarationAllowGroupInvites::None => DeclarationAllowGroupInvites::None,
126 DeclarationAllowGroupInvites::Following => {
127 DeclarationAllowGroupInvites::Following
128 }
129 DeclarationAllowGroupInvites::Other(v) => {
130 DeclarationAllowGroupInvites::Other(v.into_static())
131 }
132 }
133 }
134}
135
136
137#[derive(Debug, Clone, PartialEq, Eq, Hash)]
138pub enum DeclarationAllowIncoming<S: BosStr = DefaultStr> {
139 All,
140 None,
141 Following,
142 Other(S),
143}
144
145impl<S: BosStr> DeclarationAllowIncoming<S> {
146 pub fn as_str(&self) -> &str {
147 match self {
148 Self::All => "all",
149 Self::None => "none",
150 Self::Following => "following",
151 Self::Other(s) => s.as_ref(),
152 }
153 }
154 pub fn from_value(s: S) -> Self {
156 match s.as_ref() {
157 "all" => Self::All,
158 "none" => Self::None,
159 "following" => Self::Following,
160 _ => Self::Other(s),
161 }
162 }
163}
164
165impl<S: BosStr> core::fmt::Display for DeclarationAllowIncoming<S> {
166 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
167 write!(f, "{}", self.as_str())
168 }
169}
170
171impl<S: BosStr> AsRef<str> for DeclarationAllowIncoming<S> {
172 fn as_ref(&self) -> &str {
173 self.as_str()
174 }
175}
176
177impl<S: BosStr> Serialize for DeclarationAllowIncoming<S> {
178 fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
179 where
180 Ser: serde::Serializer,
181 {
182 serializer.serialize_str(self.as_str())
183 }
184}
185
186impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de>
187for DeclarationAllowIncoming<S> {
188 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
189 where
190 D: serde::Deserializer<'de>,
191 {
192 let s = S::deserialize(deserializer)?;
193 Ok(Self::from_value(s))
194 }
195}
196
197impl<S: BosStr + Default> Default for DeclarationAllowIncoming<S> {
198 fn default() -> Self {
199 Self::Other(Default::default())
200 }
201}
202
203impl<S: BosStr> jacquard_common::IntoStatic for DeclarationAllowIncoming<S>
204where
205 S: BosStr + jacquard_common::IntoStatic,
206 S::Output: BosStr,
207{
208 type Output = DeclarationAllowIncoming<S::Output>;
209 fn into_static(self) -> Self::Output {
210 match self {
211 DeclarationAllowIncoming::All => DeclarationAllowIncoming::All,
212 DeclarationAllowIncoming::None => DeclarationAllowIncoming::None,
213 DeclarationAllowIncoming::Following => DeclarationAllowIncoming::Following,
214 DeclarationAllowIncoming::Other(v) => {
215 DeclarationAllowIncoming::Other(v.into_static())
216 }
217 }
218 }
219}
220
221#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
224#[serde(rename_all = "camelCase")]
225pub struct DeclarationGetRecordOutput<S: BosStr = DefaultStr> {
226 #[serde(skip_serializing_if = "Option::is_none")]
227 pub cid: Option<Cid<S>>,
228 pub uri: AtUri<S>,
229 pub value: Declaration<S>,
230}
231
232impl<S: BosStr> Declaration<S> {
233 pub fn uri(uri: S) -> Result<RecordUri<S, DeclarationRecord>, UriError> {
234 RecordUri::try_from_uri(AtUri::new(uri)?)
235 }
236}
237
238#[derive(Debug, Serialize, Deserialize)]
241pub struct DeclarationRecord;
242impl XrpcResp for DeclarationRecord {
243 const NSID: &'static str = "chat.bsky.actor.declaration";
244 const ENCODING: &'static str = "application/json";
245 type Output<S: BosStr> = DeclarationGetRecordOutput<S>;
246 type Err = RecordError;
247}
248
249impl<S: BosStr> From<DeclarationGetRecordOutput<S>> for Declaration<S> {
250 fn from(output: DeclarationGetRecordOutput<S>) -> Self {
251 output.value
252 }
253}
254
255impl<S: BosStr> Collection for Declaration<S> {
256 const NSID: &'static str = "chat.bsky.actor.declaration";
257 type Record = DeclarationRecord;
258}
259
260impl Collection for DeclarationRecord {
261 const NSID: &'static str = "chat.bsky.actor.declaration";
262 type Record = DeclarationRecord;
263}
264
265impl<S: BosStr> LexiconSchema for Declaration<S> {
266 fn nsid() -> &'static str {
267 "chat.bsky.actor.declaration"
268 }
269 fn def_name() -> &'static str {
270 "main"
271 }
272 fn lexicon_doc() -> LexiconDoc<'static> {
273 lexicon_doc_chat_bsky_actor_declaration()
274 }
275 fn validate(&self) -> Result<(), ConstraintError> {
276 Ok(())
277 }
278}
279
280pub mod declaration_state {
281
282 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
283 #[allow(unused)]
284 use ::core::marker::PhantomData;
285 mod sealed {
286 pub trait Sealed {}
287 }
288 pub trait State: sealed::Sealed {
290 type AllowIncoming;
291 }
292 pub struct Empty(());
294 impl sealed::Sealed for Empty {}
295 impl State for Empty {
296 type AllowIncoming = Unset;
297 }
298 pub struct SetAllowIncoming<St: State = Empty>(PhantomData<fn() -> St>);
300 impl<St: State> sealed::Sealed for SetAllowIncoming<St> {}
301 impl<St: State> State for SetAllowIncoming<St> {
302 type AllowIncoming = Set<members::allow_incoming>;
303 }
304 #[allow(non_camel_case_types)]
306 pub mod members {
307 pub struct allow_incoming(());
309 }
310}
311
312pub struct DeclarationBuilder<St: declaration_state::State, S: BosStr = DefaultStr> {
314 _state: PhantomData<fn() -> St>,
315 _fields: (
316 Option<DeclarationAllowGroupInvites<S>>,
317 Option<DeclarationAllowIncoming<S>>,
318 ),
319 _type: PhantomData<fn() -> S>,
320}
321
322impl Declaration<DefaultStr> {
323 pub fn new() -> DeclarationBuilder<declaration_state::Empty, DefaultStr> {
325 DeclarationBuilder::new()
326 }
327}
328
329impl<S: BosStr> Declaration<S> {
330 pub fn builder() -> DeclarationBuilder<declaration_state::Empty, S> {
332 DeclarationBuilder::builder()
333 }
334}
335
336impl DeclarationBuilder<declaration_state::Empty, DefaultStr> {
337 pub fn new() -> Self {
339 DeclarationBuilder {
340 _state: PhantomData,
341 _fields: (None, None),
342 _type: PhantomData,
343 }
344 }
345}
346
347impl<S: BosStr> DeclarationBuilder<declaration_state::Empty, S> {
348 pub fn builder() -> Self {
350 DeclarationBuilder {
351 _state: PhantomData,
352 _fields: (None, None),
353 _type: PhantomData,
354 }
355 }
356}
357
358impl<St: declaration_state::State, S: BosStr> DeclarationBuilder<St, S> {
359 pub fn allow_group_invites(
361 mut self,
362 value: impl Into<Option<DeclarationAllowGroupInvites<S>>>,
363 ) -> Self {
364 self._fields.0 = value.into();
365 self
366 }
367 pub fn maybe_allow_group_invites(
369 mut self,
370 value: Option<DeclarationAllowGroupInvites<S>>,
371 ) -> Self {
372 self._fields.0 = value;
373 self
374 }
375}
376
377impl<St, S: BosStr> DeclarationBuilder<St, S>
378where
379 St: declaration_state::State,
380 St::AllowIncoming: declaration_state::IsUnset,
381{
382 pub fn allow_incoming(
384 mut self,
385 value: impl Into<DeclarationAllowIncoming<S>>,
386 ) -> DeclarationBuilder<declaration_state::SetAllowIncoming<St>, S> {
387 self._fields.1 = Option::Some(value.into());
388 DeclarationBuilder {
389 _state: PhantomData,
390 _fields: self._fields,
391 _type: PhantomData,
392 }
393 }
394}
395
396impl<St, S: BosStr> DeclarationBuilder<St, S>
397where
398 St: declaration_state::State,
399 St::AllowIncoming: declaration_state::IsSet,
400{
401 pub fn build(self) -> Declaration<S> {
403 Declaration {
404 allow_group_invites: self._fields.0,
405 allow_incoming: self._fields.1.unwrap(),
406 extra_data: Default::default(),
407 }
408 }
409 pub fn build_with_data(
411 self,
412 extra_data: BTreeMap<SmolStr, Data<S>>,
413 ) -> Declaration<S> {
414 Declaration {
415 allow_group_invites: self._fields.0,
416 allow_incoming: self._fields.1.unwrap(),
417 extra_data: Some(extra_data),
418 }
419 }
420}
421
422fn lexicon_doc_chat_bsky_actor_declaration() -> LexiconDoc<'static> {
423 #[allow(unused_imports)]
424 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
425 use jacquard_lexicon::lexicon::*;
426 use alloc::collections::BTreeMap;
427 LexiconDoc {
428 lexicon: Lexicon::Lexicon1,
429 id: CowStr::new_static("chat.bsky.actor.declaration"),
430 defs: {
431 let mut map = BTreeMap::new();
432 map.insert(
433 SmolStr::new_static("main"),
434 LexUserType::Record(LexRecord {
435 description: Some(
436 CowStr::new_static("A declaration of a Bluesky chat account."),
437 ),
438 key: Some(CowStr::new_static("literal:self")),
439 record: LexRecordRecord::Object(LexObject {
440 required: Some(vec![SmolStr::new_static("allowIncoming")]),
441 properties: {
442 #[allow(unused_mut)]
443 let mut map = BTreeMap::new();
444 map.insert(
445 SmolStr::new_static("allowGroupInvites"),
446 LexObjectProperty::String(LexString {
447 description: Some(
448 CowStr::new_static(
449 "[NOTE: This is under active development and should be considered unstable while this note is here]. Declaration about group chat invitation preferences for the record owner.",
450 ),
451 ),
452 ..Default::default()
453 }),
454 );
455 map.insert(
456 SmolStr::new_static("allowIncoming"),
457 LexObjectProperty::String(LexString {
458 ..Default::default()
459 }),
460 );
461 map
462 },
463 ..Default::default()
464 }),
465 ..Default::default()
466 }),
467 );
468 map
469 },
470 ..Default::default()
471 }
472}