jacquard_api/app_bsky/notification/
register_push.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14use jacquard_common::types::string::Did;
15use jacquard_derive::{IntoStatic, lexicon};
16use serde::{Serialize, Deserialize};
17
18#[lexicon]
19#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
20#[serde(rename_all = "camelCase")]
21pub struct RegisterPush<'a> {
22 #[serde(skip_serializing_if = "Option::is_none")]
24 pub age_restricted: Option<bool>,
25 #[serde(borrow)]
26 pub app_id: CowStr<'a>,
27 #[serde(borrow)]
28 pub platform: RegisterPushPlatform<'a>,
29 #[serde(borrow)]
30 pub service_did: Did<'a>,
31 #[serde(borrow)]
32 pub token: CowStr<'a>,
33}
34
35
36#[derive(Debug, Clone, PartialEq, Eq, Hash)]
37pub enum RegisterPushPlatform<'a> {
38 Ios,
39 Android,
40 Web,
41 Other(CowStr<'a>),
42}
43
44impl<'a> RegisterPushPlatform<'a> {
45 pub fn as_str(&self) -> &str {
46 match self {
47 Self::Ios => "ios",
48 Self::Android => "android",
49 Self::Web => "web",
50 Self::Other(s) => s.as_ref(),
51 }
52 }
53}
54
55impl<'a> From<&'a str> for RegisterPushPlatform<'a> {
56 fn from(s: &'a str) -> Self {
57 match s {
58 "ios" => Self::Ios,
59 "android" => Self::Android,
60 "web" => Self::Web,
61 _ => Self::Other(CowStr::from(s)),
62 }
63 }
64}
65
66impl<'a> From<String> for RegisterPushPlatform<'a> {
67 fn from(s: String) -> Self {
68 match s.as_str() {
69 "ios" => Self::Ios,
70 "android" => Self::Android,
71 "web" => Self::Web,
72 _ => Self::Other(CowStr::from(s)),
73 }
74 }
75}
76
77impl<'a> core::fmt::Display for RegisterPushPlatform<'a> {
78 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
79 write!(f, "{}", self.as_str())
80 }
81}
82
83impl<'a> AsRef<str> for RegisterPushPlatform<'a> {
84 fn as_ref(&self) -> &str {
85 self.as_str()
86 }
87}
88
89impl<'a> serde::Serialize for RegisterPushPlatform<'a> {
90 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
91 where
92 S: serde::Serializer,
93 {
94 serializer.serialize_str(self.as_str())
95 }
96}
97
98impl<'de, 'a> serde::Deserialize<'de> for RegisterPushPlatform<'a>
99where
100 'de: 'a,
101{
102 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
103 where
104 D: serde::Deserializer<'de>,
105 {
106 let s = <&'de str>::deserialize(deserializer)?;
107 Ok(Self::from(s))
108 }
109}
110
111impl<'a> Default for RegisterPushPlatform<'a> {
112 fn default() -> Self {
113 Self::Other(Default::default())
114 }
115}
116
117impl jacquard_common::IntoStatic for RegisterPushPlatform<'_> {
118 type Output = RegisterPushPlatform<'static>;
119 fn into_static(self) -> Self::Output {
120 match self {
121 RegisterPushPlatform::Ios => RegisterPushPlatform::Ios,
122 RegisterPushPlatform::Android => RegisterPushPlatform::Android,
123 RegisterPushPlatform::Web => RegisterPushPlatform::Web,
124 RegisterPushPlatform::Other(v) => {
125 RegisterPushPlatform::Other(v.into_static())
126 }
127 }
128 }
129}
130
131pub struct RegisterPushResponse;
133impl jacquard_common::xrpc::XrpcResp for RegisterPushResponse {
134 const NSID: &'static str = "app.bsky.notification.registerPush";
135 const ENCODING: &'static str = "application/json";
136 type Output<'de> = ();
137 type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
138}
139
140impl<'a> jacquard_common::xrpc::XrpcRequest for RegisterPush<'a> {
141 const NSID: &'static str = "app.bsky.notification.registerPush";
142 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
143 "application/json",
144 );
145 type Response = RegisterPushResponse;
146}
147
148pub struct RegisterPushRequest;
150impl jacquard_common::xrpc::XrpcEndpoint for RegisterPushRequest {
151 const PATH: &'static str = "/xrpc/app.bsky.notification.registerPush";
152 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
153 "application/json",
154 );
155 type Request<'de> = RegisterPush<'de>;
156 type Response = RegisterPushResponse;
157}
158
159pub mod register_push_state {
160
161 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
162 #[allow(unused)]
163 use ::core::marker::PhantomData;
164 mod sealed {
165 pub trait Sealed {}
166 }
167 pub trait State: sealed::Sealed {
169 type ServiceDid;
170 type Token;
171 type Platform;
172 type AppId;
173 }
174 pub struct Empty(());
176 impl sealed::Sealed for Empty {}
177 impl State for Empty {
178 type ServiceDid = Unset;
179 type Token = Unset;
180 type Platform = Unset;
181 type AppId = Unset;
182 }
183 pub struct SetServiceDid<S: State = Empty>(PhantomData<fn() -> S>);
185 impl<S: State> sealed::Sealed for SetServiceDid<S> {}
186 impl<S: State> State for SetServiceDid<S> {
187 type ServiceDid = Set<members::service_did>;
188 type Token = S::Token;
189 type Platform = S::Platform;
190 type AppId = S::AppId;
191 }
192 pub struct SetToken<S: State = Empty>(PhantomData<fn() -> S>);
194 impl<S: State> sealed::Sealed for SetToken<S> {}
195 impl<S: State> State for SetToken<S> {
196 type ServiceDid = S::ServiceDid;
197 type Token = Set<members::token>;
198 type Platform = S::Platform;
199 type AppId = S::AppId;
200 }
201 pub struct SetPlatform<S: State = Empty>(PhantomData<fn() -> S>);
203 impl<S: State> sealed::Sealed for SetPlatform<S> {}
204 impl<S: State> State for SetPlatform<S> {
205 type ServiceDid = S::ServiceDid;
206 type Token = S::Token;
207 type Platform = Set<members::platform>;
208 type AppId = S::AppId;
209 }
210 pub struct SetAppId<S: State = Empty>(PhantomData<fn() -> S>);
212 impl<S: State> sealed::Sealed for SetAppId<S> {}
213 impl<S: State> State for SetAppId<S> {
214 type ServiceDid = S::ServiceDid;
215 type Token = S::Token;
216 type Platform = S::Platform;
217 type AppId = Set<members::app_id>;
218 }
219 #[allow(non_camel_case_types)]
221 pub mod members {
222 pub struct service_did(());
224 pub struct token(());
226 pub struct platform(());
228 pub struct app_id(());
230 }
231}
232
233pub struct RegisterPushBuilder<'a, S: register_push_state::State> {
235 _state: PhantomData<fn() -> S>,
236 _fields: (
237 Option<bool>,
238 Option<CowStr<'a>>,
239 Option<RegisterPushPlatform<'a>>,
240 Option<Did<'a>>,
241 Option<CowStr<'a>>,
242 ),
243 _lifetime: PhantomData<&'a ()>,
244}
245
246impl<'a> RegisterPush<'a> {
247 pub fn new() -> RegisterPushBuilder<'a, register_push_state::Empty> {
249 RegisterPushBuilder::new()
250 }
251}
252
253impl<'a> RegisterPushBuilder<'a, register_push_state::Empty> {
254 pub fn new() -> Self {
256 RegisterPushBuilder {
257 _state: PhantomData,
258 _fields: (None, None, None, None, None),
259 _lifetime: PhantomData,
260 }
261 }
262}
263
264impl<'a, S: register_push_state::State> RegisterPushBuilder<'a, S> {
265 pub fn age_restricted(mut self, value: impl Into<Option<bool>>) -> Self {
267 self._fields.0 = value.into();
268 self
269 }
270 pub fn maybe_age_restricted(mut self, value: Option<bool>) -> Self {
272 self._fields.0 = value;
273 self
274 }
275}
276
277impl<'a, S> RegisterPushBuilder<'a, S>
278where
279 S: register_push_state::State,
280 S::AppId: register_push_state::IsUnset,
281{
282 pub fn app_id(
284 mut self,
285 value: impl Into<CowStr<'a>>,
286 ) -> RegisterPushBuilder<'a, register_push_state::SetAppId<S>> {
287 self._fields.1 = Option::Some(value.into());
288 RegisterPushBuilder {
289 _state: PhantomData,
290 _fields: self._fields,
291 _lifetime: PhantomData,
292 }
293 }
294}
295
296impl<'a, S> RegisterPushBuilder<'a, S>
297where
298 S: register_push_state::State,
299 S::Platform: register_push_state::IsUnset,
300{
301 pub fn platform(
303 mut self,
304 value: impl Into<RegisterPushPlatform<'a>>,
305 ) -> RegisterPushBuilder<'a, register_push_state::SetPlatform<S>> {
306 self._fields.2 = Option::Some(value.into());
307 RegisterPushBuilder {
308 _state: PhantomData,
309 _fields: self._fields,
310 _lifetime: PhantomData,
311 }
312 }
313}
314
315impl<'a, S> RegisterPushBuilder<'a, S>
316where
317 S: register_push_state::State,
318 S::ServiceDid: register_push_state::IsUnset,
319{
320 pub fn service_did(
322 mut self,
323 value: impl Into<Did<'a>>,
324 ) -> RegisterPushBuilder<'a, register_push_state::SetServiceDid<S>> {
325 self._fields.3 = Option::Some(value.into());
326 RegisterPushBuilder {
327 _state: PhantomData,
328 _fields: self._fields,
329 _lifetime: PhantomData,
330 }
331 }
332}
333
334impl<'a, S> RegisterPushBuilder<'a, S>
335where
336 S: register_push_state::State,
337 S::Token: register_push_state::IsUnset,
338{
339 pub fn token(
341 mut self,
342 value: impl Into<CowStr<'a>>,
343 ) -> RegisterPushBuilder<'a, register_push_state::SetToken<S>> {
344 self._fields.4 = Option::Some(value.into());
345 RegisterPushBuilder {
346 _state: PhantomData,
347 _fields: self._fields,
348 _lifetime: PhantomData,
349 }
350 }
351}
352
353impl<'a, S> RegisterPushBuilder<'a, S>
354where
355 S: register_push_state::State,
356 S::ServiceDid: register_push_state::IsSet,
357 S::Token: register_push_state::IsSet,
358 S::Platform: register_push_state::IsSet,
359 S::AppId: register_push_state::IsSet,
360{
361 pub fn build(self) -> RegisterPush<'a> {
363 RegisterPush {
364 age_restricted: self._fields.0,
365 app_id: self._fields.1.unwrap(),
366 platform: self._fields.2.unwrap(),
367 service_did: self._fields.3.unwrap(),
368 token: self._fields.4.unwrap(),
369 extra_data: Default::default(),
370 }
371 }
372 pub fn build_with_data(
374 self,
375 extra_data: BTreeMap<
376 jacquard_common::deps::smol_str::SmolStr,
377 jacquard_common::types::value::Data<'a>,
378 >,
379 ) -> RegisterPush<'a> {
380 RegisterPush {
381 age_restricted: self._fields.0,
382 app_id: self._fields.1.unwrap(),
383 platform: self._fields.2.unwrap(),
384 service_did: self._fields.3.unwrap(),
385 token: self._fields.4.unwrap(),
386 extra_data: Some(extra_data),
387 }
388 }
389}