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::{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 = "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> for DeclarationAllowSubscriptions<S> {
98 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
99 where
100 D: serde::Deserializer<'de>,
101 {
102 let s = S::deserialize(deserializer)?;
103 Ok(Self::from_value(s))
104 }
105}
106
107impl<S: BosStr + Default> Default for DeclarationAllowSubscriptions<S> {
108 fn default() -> Self {
109 Self::Other(Default::default())
110 }
111}
112
113impl<S: BosStr> jacquard_common::IntoStatic for DeclarationAllowSubscriptions<S>
114where
115 S: BosStr + jacquard_common::IntoStatic,
116 S::Output: BosStr,
117{
118 type Output = DeclarationAllowSubscriptions<S::Output>;
119 fn into_static(self) -> Self::Output {
120 match self {
121 DeclarationAllowSubscriptions::Followers => DeclarationAllowSubscriptions::Followers,
122 DeclarationAllowSubscriptions::Mutuals => DeclarationAllowSubscriptions::Mutuals,
123 DeclarationAllowSubscriptions::None => DeclarationAllowSubscriptions::None,
124 DeclarationAllowSubscriptions::Other(v) => {
125 DeclarationAllowSubscriptions::Other(v.into_static())
126 }
127 }
128 }
129}
130
131#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
134#[serde(rename_all = "camelCase")]
135pub struct DeclarationGetRecordOutput<S: BosStr = DefaultStr> {
136 #[serde(skip_serializing_if = "Option::is_none")]
137 pub cid: Option<Cid<S>>,
138 pub uri: AtUri<S>,
139 pub value: Declaration<S>,
140}
141
142impl<S: BosStr> Declaration<S> {
143 pub fn uri(uri: S) -> Result<RecordUri<S, DeclarationRecord>, UriError> {
144 RecordUri::try_from_uri(AtUri::new(uri)?)
145 }
146}
147
148#[derive(Debug, Serialize, Deserialize)]
151pub struct DeclarationRecord;
152impl XrpcResp for DeclarationRecord {
153 const NSID: &'static str = "app.bsky.notification.declaration";
154 const ENCODING: &'static str = "application/json";
155 type Output<S: BosStr> = DeclarationGetRecordOutput<S>;
156 type Err = RecordError;
157}
158
159impl<S: BosStr> From<DeclarationGetRecordOutput<S>> for Declaration<S> {
160 fn from(output: DeclarationGetRecordOutput<S>) -> Self {
161 output.value
162 }
163}
164
165impl<S: BosStr> Collection for Declaration<S> {
166 const NSID: &'static str = "app.bsky.notification.declaration";
167 type Record = DeclarationRecord;
168}
169
170impl Collection for DeclarationRecord {
171 const NSID: &'static str = "app.bsky.notification.declaration";
172 type Record = DeclarationRecord;
173}
174
175impl<S: BosStr> LexiconSchema for Declaration<S> {
176 fn nsid() -> &'static str {
177 "app.bsky.notification.declaration"
178 }
179 fn def_name() -> &'static str {
180 "main"
181 }
182 fn lexicon_doc() -> LexiconDoc<'static> {
183 lexicon_doc_app_bsky_notification_declaration()
184 }
185 fn validate(&self) -> Result<(), ConstraintError> {
186 Ok(())
187 }
188}
189
190pub mod declaration_state {
191
192 pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
193 #[allow(unused)]
194 use ::core::marker::PhantomData;
195 mod sealed {
196 pub trait Sealed {}
197 }
198 pub trait State: sealed::Sealed {
200 type AllowSubscriptions;
201 }
202 pub struct Empty(());
204 impl sealed::Sealed for Empty {}
205 impl State for Empty {
206 type AllowSubscriptions = Unset;
207 }
208 pub struct SetAllowSubscriptions<St: State = Empty>(PhantomData<fn() -> St>);
210 impl<St: State> sealed::Sealed for SetAllowSubscriptions<St> {}
211 impl<St: State> State for SetAllowSubscriptions<St> {
212 type AllowSubscriptions = Set<members::allow_subscriptions>;
213 }
214 #[allow(non_camel_case_types)]
216 pub mod members {
217 pub struct allow_subscriptions(());
219 }
220}
221
222pub struct DeclarationBuilder<St: declaration_state::State, S: BosStr = DefaultStr> {
224 _state: PhantomData<fn() -> St>,
225 _fields: (Option<DeclarationAllowSubscriptions<S>>,),
226 _type: PhantomData<fn() -> S>,
227}
228
229impl Declaration<DefaultStr> {
230 pub fn new() -> DeclarationBuilder<declaration_state::Empty, DefaultStr> {
232 DeclarationBuilder::new()
233 }
234}
235
236impl<S: BosStr> Declaration<S> {
237 pub fn builder() -> DeclarationBuilder<declaration_state::Empty, S> {
239 DeclarationBuilder::builder()
240 }
241}
242
243impl DeclarationBuilder<declaration_state::Empty, DefaultStr> {
244 pub fn new() -> Self {
246 DeclarationBuilder {
247 _state: PhantomData,
248 _fields: (None,),
249 _type: PhantomData,
250 }
251 }
252}
253
254impl<S: BosStr> DeclarationBuilder<declaration_state::Empty, S> {
255 pub fn builder() -> Self {
257 DeclarationBuilder {
258 _state: PhantomData,
259 _fields: (None,),
260 _type: PhantomData,
261 }
262 }
263}
264
265impl<St, S: BosStr> DeclarationBuilder<St, S>
266where
267 St: declaration_state::State,
268 St::AllowSubscriptions: declaration_state::IsUnset,
269{
270 pub fn allow_subscriptions(
272 mut self,
273 value: impl Into<DeclarationAllowSubscriptions<S>>,
274 ) -> DeclarationBuilder<declaration_state::SetAllowSubscriptions<St>, S> {
275 self._fields.0 = Option::Some(value.into());
276 DeclarationBuilder {
277 _state: PhantomData,
278 _fields: self._fields,
279 _type: PhantomData,
280 }
281 }
282}
283
284impl<St, S: BosStr> DeclarationBuilder<St, S>
285where
286 St: declaration_state::State,
287 St::AllowSubscriptions: declaration_state::IsSet,
288{
289 pub fn build(self) -> Declaration<S> {
291 Declaration {
292 allow_subscriptions: self._fields.0.unwrap(),
293 extra_data: Default::default(),
294 }
295 }
296 pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Declaration<S> {
298 Declaration {
299 allow_subscriptions: self._fields.0.unwrap(),
300 extra_data: Some(extra_data),
301 }
302 }
303}
304
305fn lexicon_doc_app_bsky_notification_declaration() -> LexiconDoc<'static> {
306 use alloc::collections::BTreeMap;
307 #[allow(unused_imports)]
308 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
309 use jacquard_lexicon::lexicon::*;
310 LexiconDoc {
311 lexicon: Lexicon::Lexicon1,
312 id: CowStr::new_static("app.bsky.notification.declaration"),
313 defs: {
314 let mut map = BTreeMap::new();
315 map.insert(
316 SmolStr::new_static("main"),
317 LexUserType::Record(LexRecord {
318 description: Some(
319 CowStr::new_static(
320 "A declaration of the user's choices related to notifications that can be produced by them.",
321 ),
322 ),
323 key: Some(CowStr::new_static("literal:self")),
324 record: LexRecordRecord::Object(LexObject {
325 required: Some(vec![SmolStr::new_static("allowSubscriptions")]),
326 properties: {
327 #[allow(unused_mut)]
328 let mut map = BTreeMap::new();
329 map.insert(
330 SmolStr::new_static("allowSubscriptions"),
331 LexObjectProperty::String(LexString {
332 description: Some(
333 CowStr::new_static(
334 "A declaration of the user's preference for allowing activity subscriptions from other users. Absence of a record implies 'followers'.",
335 ),
336 ),
337 ..Default::default()
338 }),
339 );
340 map
341 },
342 ..Default::default()
343 }),
344 ..Default::default()
345 }),
346 );
347 map
348 },
349 ..Default::default()
350 }
351}