jacquard_api/app_bsky/notification/
declaration.rs1#[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 = "app.bsky.notification.declaration",
36 tag = "$type",
37 bound(deserialize = "S: Deserialize<'de> + BosStr")
38)]
39pub struct Declaration<S: BosStr = DefaultStr> {
40 pub allow_subscriptions: DeclarationAllowSubscriptions<S>,
42 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
43 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
44}
45
46#[derive(Debug, Clone, PartialEq, Eq, Hash)]
49pub enum DeclarationAllowSubscriptions<S: BosStr = DefaultStr> {
50 Followers,
51 Mutuals,
52 None,
53 Other(S),
54}
55
56impl<S: BosStr> DeclarationAllowSubscriptions<S> {
57 pub fn as_str(&self) -> &str {
58 match self {
59 Self::Followers => "followers",
60 Self::Mutuals => "mutuals",
61 Self::None => "none",
62 Self::Other(s) => s.as_ref(),
63 }
64 }
65 pub fn from_value(s: S) -> Self {
67 match s.as_ref() {
68 "followers" => Self::Followers,
69 "mutuals" => Self::Mutuals,
70 "none" => Self::None,
71 _ => Self::Other(s),
72 }
73 }
74}
75
76impl<S: BosStr> core::fmt::Display for DeclarationAllowSubscriptions<S> {
77 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
78 write!(f, "{}", self.as_str())
79 }
80}
81
82impl<S: BosStr> AsRef<str> for DeclarationAllowSubscriptions<S> {
83 fn as_ref(&self) -> &str {
84 self.as_str()
85 }
86}
87
88impl<S: BosStr> Serialize for DeclarationAllowSubscriptions<S> {
89 fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
90 where
91 Ser: serde::Serializer,
92 {
93 serializer.serialize_str(self.as_str())
94 }
95}
96
97impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de>
98for DeclarationAllowSubscriptions<S> {
99 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
100 where
101 D: serde::Deserializer<'de>,
102 {
103 let s = S::deserialize(deserializer)?;
104 Ok(Self::from_value(s))
105 }
106}
107
108impl<S: BosStr + Default> Default for DeclarationAllowSubscriptions<S> {
109 fn default() -> Self {
110 Self::Other(Default::default())
111 }
112}
113
114impl<S: BosStr> jacquard_common::IntoStatic for DeclarationAllowSubscriptions<S>
115where
116 S: BosStr + jacquard_common::IntoStatic,
117 S::Output: BosStr,
118{
119 type Output = DeclarationAllowSubscriptions<S::Output>;
120 fn into_static(self) -> Self::Output {
121 match self {
122 DeclarationAllowSubscriptions::Followers => {
123 DeclarationAllowSubscriptions::Followers
124 }
125 DeclarationAllowSubscriptions::Mutuals => {
126 DeclarationAllowSubscriptions::Mutuals
127 }
128 DeclarationAllowSubscriptions::None => DeclarationAllowSubscriptions::None,
129 DeclarationAllowSubscriptions::Other(v) => {
130 DeclarationAllowSubscriptions::Other(v.into_static())
131 }
132 }
133 }
134}
135
136#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
139#[serde(rename_all = "camelCase")]
140pub struct DeclarationGetRecordOutput<S: BosStr = DefaultStr> {
141 #[serde(skip_serializing_if = "Option::is_none")]
142 pub cid: Option<Cid<S>>,
143 pub uri: AtUri<S>,
144 pub value: Declaration<S>,
145}
146
147impl<S: BosStr> Declaration<S> {
148 pub fn uri(uri: S) -> Result<RecordUri<S, DeclarationRecord>, UriError> {
149 RecordUri::try_from_uri(AtUri::new(uri)?)
150 }
151}
152
153#[derive(Debug, Serialize, Deserialize)]
156pub struct DeclarationRecord;
157impl XrpcResp for DeclarationRecord {
158 const NSID: &'static str = "app.bsky.notification.declaration";
159 const ENCODING: &'static str = "application/json";
160 type Output<S: BosStr> = DeclarationGetRecordOutput<S>;
161 type Err = RecordError;
162}
163
164impl<S: BosStr> From<DeclarationGetRecordOutput<S>> for Declaration<S> {
165 fn from(output: DeclarationGetRecordOutput<S>) -> Self {
166 output.value
167 }
168}
169
170impl<S: BosStr> Collection for Declaration<S> {
171 const NSID: &'static str = "app.bsky.notification.declaration";
172 type Record = DeclarationRecord;
173}
174
175impl Collection for DeclarationRecord {
176 const NSID: &'static str = "app.bsky.notification.declaration";
177 type Record = DeclarationRecord;
178}
179
180impl<S: BosStr> LexiconSchema for Declaration<S> {
181 fn nsid() -> &'static str {
182 "app.bsky.notification.declaration"
183 }
184 fn def_name() -> &'static str {
185 "main"
186 }
187 fn lexicon_doc() -> LexiconDoc<'static> {
188 lexicon_doc_app_bsky_notification_declaration()
189 }
190 fn validate(&self) -> Result<(), ConstraintError> {
191 Ok(())
192 }
193}
194
195pub mod declaration_state {
196
197 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
198 #[allow(unused)]
199 use ::core::marker::PhantomData;
200 mod sealed {
201 pub trait Sealed {}
202 }
203 pub trait State: sealed::Sealed {
205 type AllowSubscriptions;
206 }
207 pub struct Empty(());
209 impl sealed::Sealed for Empty {}
210 impl State for Empty {
211 type AllowSubscriptions = Unset;
212 }
213 pub struct SetAllowSubscriptions<St: State = Empty>(PhantomData<fn() -> St>);
215 impl<St: State> sealed::Sealed for SetAllowSubscriptions<St> {}
216 impl<St: State> State for SetAllowSubscriptions<St> {
217 type AllowSubscriptions = Set<members::allow_subscriptions>;
218 }
219 #[allow(non_camel_case_types)]
221 pub mod members {
222 pub struct allow_subscriptions(());
224 }
225}
226
227pub struct DeclarationBuilder<St: declaration_state::State, S: BosStr = DefaultStr> {
229 _state: PhantomData<fn() -> St>,
230 _fields: (Option<DeclarationAllowSubscriptions<S>>,),
231 _type: PhantomData<fn() -> S>,
232}
233
234impl Declaration<DefaultStr> {
235 pub fn new() -> DeclarationBuilder<declaration_state::Empty, DefaultStr> {
237 DeclarationBuilder::new()
238 }
239}
240
241impl<S: BosStr> Declaration<S> {
242 pub fn builder() -> DeclarationBuilder<declaration_state::Empty, S> {
244 DeclarationBuilder::builder()
245 }
246}
247
248impl DeclarationBuilder<declaration_state::Empty, DefaultStr> {
249 pub fn new() -> Self {
251 DeclarationBuilder {
252 _state: PhantomData,
253 _fields: (None,),
254 _type: PhantomData,
255 }
256 }
257}
258
259impl<S: BosStr> DeclarationBuilder<declaration_state::Empty, S> {
260 pub fn builder() -> Self {
262 DeclarationBuilder {
263 _state: PhantomData,
264 _fields: (None,),
265 _type: PhantomData,
266 }
267 }
268}
269
270impl<St, S: BosStr> DeclarationBuilder<St, S>
271where
272 St: declaration_state::State,
273 St::AllowSubscriptions: declaration_state::IsUnset,
274{
275 pub fn allow_subscriptions(
277 mut self,
278 value: impl Into<DeclarationAllowSubscriptions<S>>,
279 ) -> DeclarationBuilder<declaration_state::SetAllowSubscriptions<St>, S> {
280 self._fields.0 = Option::Some(value.into());
281 DeclarationBuilder {
282 _state: PhantomData,
283 _fields: self._fields,
284 _type: PhantomData,
285 }
286 }
287}
288
289impl<St, S: BosStr> DeclarationBuilder<St, S>
290where
291 St: declaration_state::State,
292 St::AllowSubscriptions: declaration_state::IsSet,
293{
294 pub fn build(self) -> Declaration<S> {
296 Declaration {
297 allow_subscriptions: self._fields.0.unwrap(),
298 extra_data: Default::default(),
299 }
300 }
301 pub fn build_with_data(
303 self,
304 extra_data: BTreeMap<SmolStr, Data<S>>,
305 ) -> Declaration<S> {
306 Declaration {
307 allow_subscriptions: self._fields.0.unwrap(),
308 extra_data: Some(extra_data),
309 }
310 }
311}
312
313fn lexicon_doc_app_bsky_notification_declaration() -> LexiconDoc<'static> {
314 #[allow(unused_imports)]
315 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
316 use jacquard_lexicon::lexicon::*;
317 use alloc::collections::BTreeMap;
318 LexiconDoc {
319 lexicon: Lexicon::Lexicon1,
320 id: CowStr::new_static("app.bsky.notification.declaration"),
321 defs: {
322 let mut map = BTreeMap::new();
323 map.insert(
324 SmolStr::new_static("main"),
325 LexUserType::Record(LexRecord {
326 description: Some(
327 CowStr::new_static(
328 "A declaration of the user's choices related to notifications that can be produced by them.",
329 ),
330 ),
331 key: Some(CowStr::new_static("literal:self")),
332 record: LexRecordRecord::Object(LexObject {
333 required: Some(vec![SmolStr::new_static("allowSubscriptions")]),
334 properties: {
335 #[allow(unused_mut)]
336 let mut map = BTreeMap::new();
337 map.insert(
338 SmolStr::new_static("allowSubscriptions"),
339 LexObjectProperty::String(LexString {
340 description: Some(
341 CowStr::new_static(
342 "A declaration of the user's preference for allowing activity subscriptions from other users. Absence of a record implies 'followers'.",
343 ),
344 ),
345 ..Default::default()
346 }),
347 );
348 map
349 },
350 ..Default::default()
351 }),
352 ..Default::default()
353 }),
354 );
355 map
356 },
357 ..Default::default()
358 }
359}