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