Skip to main content

jacquard_api/com_atproto/server/
create_app_password.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: com.atproto.server.createAppPassword
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[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::string::Datetime;
19use jacquard_common::types::value::Data;
20use jacquard_derive::{IntoStatic, open_union};
21use jacquard_lexicon::lexicon::LexiconDoc;
22use jacquard_lexicon::schema::LexiconSchema;
23
24use crate::com_atproto::server::create_app_password;
25#[allow(unused_imports)]
26use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
27use serde::{Deserialize, Serialize};
28
29#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
30#[serde(
31    rename_all = "camelCase",
32    bound(deserialize = "S: Deserialize<'de> + BosStr")
33)]
34pub struct AppPassword<S: BosStr = DefaultStr> {
35    pub created_at: Datetime,
36    pub name: S,
37    pub password: S,
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub privileged: Option<bool>,
40    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
41    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
42}
43
44#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
45#[serde(
46    rename_all = "camelCase",
47    bound(deserialize = "S: Deserialize<'de> + BosStr")
48)]
49pub struct CreateAppPassword<S: BosStr = DefaultStr> {
50    ///A short name for the App Password, to help distinguish them.
51    pub name: S,
52    ///If an app password has 'privileged' access to possibly sensitive account state. Meant for use with trusted clients.
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub privileged: Option<bool>,
55    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
56    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
57}
58
59#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
60#[serde(
61    rename_all = "camelCase",
62    bound(deserialize = "S: Deserialize<'de> + BosStr")
63)]
64pub struct CreateAppPasswordOutput<S: BosStr = DefaultStr> {
65    #[serde(flatten)]
66    pub value: Data<S>,
67    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
68    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
69}
70
71#[derive(
72    Serialize, Deserialize, Debug, Clone, PartialEq, Eq, thiserror::Error, miette::Diagnostic,
73)]
74#[serde(tag = "error", content = "message")]
75pub enum CreateAppPasswordError {
76    #[serde(rename = "AccountTakedown")]
77    AccountTakedown(Option<SmolStr>),
78    /// Catch-all for unknown error codes.
79    #[serde(untagged)]
80    Other {
81        error: SmolStr,
82        message: Option<SmolStr>,
83    },
84}
85
86impl core::fmt::Display for CreateAppPasswordError {
87    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
88        match self {
89            Self::AccountTakedown(msg) => {
90                write!(f, "AccountTakedown")?;
91                if let Some(msg) = msg {
92                    write!(f, ": {}", msg)?;
93                }
94                Ok(())
95            }
96            Self::Other { error, message } => {
97                write!(f, "{}", error)?;
98                if let Some(msg) = message {
99                    write!(f, ": {}", msg)?;
100                }
101                Ok(())
102            }
103        }
104    }
105}
106
107impl<S: BosStr> LexiconSchema for AppPassword<S> {
108    fn nsid() -> &'static str {
109        "com.atproto.server.createAppPassword"
110    }
111    fn def_name() -> &'static str {
112        "appPassword"
113    }
114    fn lexicon_doc() -> LexiconDoc<'static> {
115        lexicon_doc_com_atproto_server_createAppPassword()
116    }
117    fn validate(&self) -> Result<(), ConstraintError> {
118        Ok(())
119    }
120}
121
122/** Response marker for the `com.atproto.server.createAppPassword` procedure.
123
124Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `CreateAppPasswordOutput<S>` for this endpoint.*/
125pub struct CreateAppPasswordResponse;
126impl jacquard_common::xrpc::XrpcResp for CreateAppPasswordResponse {
127    const NSID: &'static str = "com.atproto.server.createAppPassword";
128    const ENCODING: &'static str = "application/json";
129    type Output<S: BosStr> = CreateAppPasswordOutput<S>;
130    type Err = CreateAppPasswordError;
131}
132
133impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CreateAppPassword<S> {
134    const NSID: &'static str = "com.atproto.server.createAppPassword";
135    const METHOD: jacquard_common::xrpc::XrpcMethod =
136        jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
137    type Response = CreateAppPasswordResponse;
138}
139
140/** Endpoint marker for the `com.atproto.server.createAppPassword` procedure.
141
142Path: `/xrpc/com.atproto.server.createAppPassword`. The request payload type is `CreateAppPassword<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
143pub struct CreateAppPasswordRequest;
144impl jacquard_common::xrpc::XrpcEndpoint for CreateAppPasswordRequest {
145    const PATH: &'static str = "/xrpc/com.atproto.server.createAppPassword";
146    const METHOD: jacquard_common::xrpc::XrpcMethod =
147        jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
148    type Request<S: BosStr> = CreateAppPassword<S>;
149    type Response = CreateAppPasswordResponse;
150}
151
152pub mod app_password_state {
153
154    pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
155    #[allow(unused)]
156    use ::core::marker::PhantomData;
157    mod sealed {
158        pub trait Sealed {}
159    }
160    /// State trait tracking which required fields have been set
161    pub trait State: sealed::Sealed {
162        type CreatedAt;
163        type Name;
164        type Password;
165    }
166    /// Empty state - all required fields are unset
167    pub struct Empty(());
168    impl sealed::Sealed for Empty {}
169    impl State for Empty {
170        type CreatedAt = Unset;
171        type Name = Unset;
172        type Password = Unset;
173    }
174    ///State transition - sets the `created_at` field to Set
175    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
176    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
177    impl<St: State> State for SetCreatedAt<St> {
178        type CreatedAt = Set<members::created_at>;
179        type Name = St::Name;
180        type Password = St::Password;
181    }
182    ///State transition - sets the `name` field to Set
183    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
184    impl<St: State> sealed::Sealed for SetName<St> {}
185    impl<St: State> State for SetName<St> {
186        type CreatedAt = St::CreatedAt;
187        type Name = Set<members::name>;
188        type Password = St::Password;
189    }
190    ///State transition - sets the `password` field to Set
191    pub struct SetPassword<St: State = Empty>(PhantomData<fn() -> St>);
192    impl<St: State> sealed::Sealed for SetPassword<St> {}
193    impl<St: State> State for SetPassword<St> {
194        type CreatedAt = St::CreatedAt;
195        type Name = St::Name;
196        type Password = Set<members::password>;
197    }
198    /// Marker types for field names
199    #[allow(non_camel_case_types)]
200    pub mod members {
201        ///Marker type for the `created_at` field
202        pub struct created_at(());
203        ///Marker type for the `name` field
204        pub struct name(());
205        ///Marker type for the `password` field
206        pub struct password(());
207    }
208}
209
210/// Builder for constructing an instance of this type.
211pub struct AppPasswordBuilder<St: app_password_state::State, S: BosStr = DefaultStr> {
212    _state: PhantomData<fn() -> St>,
213    _fields: (Option<Datetime>, Option<S>, Option<S>, Option<bool>),
214    _type: PhantomData<fn() -> S>,
215}
216
217impl AppPassword<DefaultStr> {
218    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
219    pub fn new() -> AppPasswordBuilder<app_password_state::Empty, DefaultStr> {
220        AppPasswordBuilder::new()
221    }
222}
223
224impl<S: BosStr> AppPassword<S> {
225    /// Create a new builder for this type
226    pub fn builder() -> AppPasswordBuilder<app_password_state::Empty, S> {
227        AppPasswordBuilder::builder()
228    }
229}
230
231impl AppPasswordBuilder<app_password_state::Empty, DefaultStr> {
232    /// Create a new builder with all fields unset, using the default string type, if needed
233    pub fn new() -> Self {
234        AppPasswordBuilder {
235            _state: PhantomData,
236            _fields: (None, None, None, None),
237            _type: PhantomData,
238        }
239    }
240}
241
242impl<S: BosStr> AppPasswordBuilder<app_password_state::Empty, S> {
243    /// Create a new builder with all fields unset
244    pub fn builder() -> Self {
245        AppPasswordBuilder {
246            _state: PhantomData,
247            _fields: (None, None, None, None),
248            _type: PhantomData,
249        }
250    }
251}
252
253impl<St, S: BosStr> AppPasswordBuilder<St, S>
254where
255    St: app_password_state::State,
256    St::CreatedAt: app_password_state::IsUnset,
257{
258    /// Set the `createdAt` field (required)
259    pub fn created_at(
260        mut self,
261        value: impl Into<Datetime>,
262    ) -> AppPasswordBuilder<app_password_state::SetCreatedAt<St>, S> {
263        self._fields.0 = Option::Some(value.into());
264        AppPasswordBuilder {
265            _state: PhantomData,
266            _fields: self._fields,
267            _type: PhantomData,
268        }
269    }
270}
271
272impl<St, S: BosStr> AppPasswordBuilder<St, S>
273where
274    St: app_password_state::State,
275    St::Name: app_password_state::IsUnset,
276{
277    /// Set the `name` field (required)
278    pub fn name(
279        mut self,
280        value: impl Into<S>,
281    ) -> AppPasswordBuilder<app_password_state::SetName<St>, S> {
282        self._fields.1 = Option::Some(value.into());
283        AppPasswordBuilder {
284            _state: PhantomData,
285            _fields: self._fields,
286            _type: PhantomData,
287        }
288    }
289}
290
291impl<St, S: BosStr> AppPasswordBuilder<St, S>
292where
293    St: app_password_state::State,
294    St::Password: app_password_state::IsUnset,
295{
296    /// Set the `password` field (required)
297    pub fn password(
298        mut self,
299        value: impl Into<S>,
300    ) -> AppPasswordBuilder<app_password_state::SetPassword<St>, S> {
301        self._fields.2 = Option::Some(value.into());
302        AppPasswordBuilder {
303            _state: PhantomData,
304            _fields: self._fields,
305            _type: PhantomData,
306        }
307    }
308}
309
310impl<St: app_password_state::State, S: BosStr> AppPasswordBuilder<St, S> {
311    /// Set the `privileged` field (optional)
312    pub fn privileged(mut self, value: impl Into<Option<bool>>) -> Self {
313        self._fields.3 = value.into();
314        self
315    }
316    /// Set the `privileged` field to an Option value (optional)
317    pub fn maybe_privileged(mut self, value: Option<bool>) -> Self {
318        self._fields.3 = value;
319        self
320    }
321}
322
323impl<St, S: BosStr> AppPasswordBuilder<St, S>
324where
325    St: app_password_state::State,
326    St::CreatedAt: app_password_state::IsSet,
327    St::Name: app_password_state::IsSet,
328    St::Password: app_password_state::IsSet,
329{
330    /// Build the final struct.
331    pub fn build(self) -> AppPassword<S> {
332        AppPassword {
333            created_at: self._fields.0.unwrap(),
334            name: self._fields.1.unwrap(),
335            password: self._fields.2.unwrap(),
336            privileged: self._fields.3,
337            extra_data: Default::default(),
338        }
339    }
340    /// Build the final struct with custom extra_data.
341    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> AppPassword<S> {
342        AppPassword {
343            created_at: self._fields.0.unwrap(),
344            name: self._fields.1.unwrap(),
345            password: self._fields.2.unwrap(),
346            privileged: self._fields.3,
347            extra_data: Some(extra_data),
348        }
349    }
350}
351
352fn lexicon_doc_com_atproto_server_createAppPassword() -> LexiconDoc<'static> {
353    use alloc::collections::BTreeMap;
354    #[allow(unused_imports)]
355    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
356    use jacquard_lexicon::lexicon::*;
357    LexiconDoc {
358        lexicon: Lexicon::Lexicon1,
359        id: CowStr::new_static("com.atproto.server.createAppPassword"),
360        defs: {
361            let mut map = BTreeMap::new();
362            map.insert(
363                SmolStr::new_static("appPassword"),
364                LexUserType::Object(LexObject {
365                    required: Some(vec![
366                        SmolStr::new_static("name"),
367                        SmolStr::new_static("password"),
368                        SmolStr::new_static("createdAt"),
369                    ]),
370                    properties: {
371                        #[allow(unused_mut)]
372                        let mut map = BTreeMap::new();
373                        map.insert(
374                            SmolStr::new_static("createdAt"),
375                            LexObjectProperty::String(LexString {
376                                format: Some(LexStringFormat::Datetime),
377                                ..Default::default()
378                            }),
379                        );
380                        map.insert(
381                            SmolStr::new_static("name"),
382                            LexObjectProperty::String(LexString {
383                                ..Default::default()
384                            }),
385                        );
386                        map.insert(
387                            SmolStr::new_static("password"),
388                            LexObjectProperty::String(LexString {
389                                ..Default::default()
390                            }),
391                        );
392                        map.insert(
393                            SmolStr::new_static("privileged"),
394                            LexObjectProperty::Boolean(LexBoolean {
395                                ..Default::default()
396                            }),
397                        );
398                        map
399                    },
400                    ..Default::default()
401                }),
402            );
403            map.insert(
404                SmolStr::new_static("main"),
405                LexUserType::XrpcProcedure(LexXrpcProcedure {
406                    input: Some(LexXrpcBody {
407                        encoding: CowStr::new_static("application/json"),
408                        schema: Some(
409                            LexXrpcBodySchema::Object(LexObject {
410                                required: Some(vec![SmolStr::new_static("name")]),
411                                properties: {
412                                    #[allow(unused_mut)]
413                                    let mut map = BTreeMap::new();
414                                    map.insert(
415                                        SmolStr::new_static("name"),
416                                        LexObjectProperty::String(LexString {
417                                            description: Some(
418                                                CowStr::new_static(
419                                                    "A short name for the App Password, to help distinguish them.",
420                                                ),
421                                            ),
422                                            ..Default::default()
423                                        }),
424                                    );
425                                    map.insert(
426                                        SmolStr::new_static("privileged"),
427                                        LexObjectProperty::Boolean(LexBoolean {
428                                            ..Default::default()
429                                        }),
430                                    );
431                                    map
432                                },
433                                ..Default::default()
434                            }),
435                        ),
436                        ..Default::default()
437                    }),
438                    ..Default::default()
439                }),
440            );
441            map
442        },
443        ..Default::default()
444    }
445}