1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::deps::smol_str::SmolStr;
14use jacquard_common::types::string::{Did, Handle};
15use jacquard_common::types::value::Data;
16use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
17use jacquard_derive::{IntoStatic, open_union};
18use serde::{Deserialize, Serialize};
19
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
21#[serde(
22 rename_all = "camelCase",
23 bound(deserialize = "S: Deserialize<'de> + BosStr")
24)]
25pub struct CreateAccount<S: BosStr = DefaultStr> {
26 #[serde(skip_serializing_if = "Option::is_none")]
28 pub did: Option<Did<S>>,
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub email: Option<S>,
31 pub handle: Handle<S>,
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub invite_code: Option<S>,
35 #[serde(skip_serializing_if = "Option::is_none")]
37 pub password: Option<S>,
38 #[serde(skip_serializing_if = "Option::is_none")]
40 pub plc_op: Option<Data<S>>,
41 #[serde(skip_serializing_if = "Option::is_none")]
43 pub recovery_key: Option<S>,
44 #[serde(skip_serializing_if = "Option::is_none")]
45 pub verification_code: Option<S>,
46 #[serde(skip_serializing_if = "Option::is_none")]
47 pub verification_phone: Option<S>,
48 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
49 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
50}
51
52#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
53#[serde(
54 rename_all = "camelCase",
55 bound(deserialize = "S: Deserialize<'de> + BosStr")
56)]
57pub struct CreateAccountOutput<S: BosStr = DefaultStr> {
58 pub access_jwt: S,
59 pub did: Did<S>,
61 #[serde(skip_serializing_if = "Option::is_none")]
63 pub did_doc: Option<Data<S>>,
64 pub handle: Handle<S>,
65 pub refresh_jwt: S,
66 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
67 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
68}
69
70#[derive(
71 Serialize, Deserialize, Debug, Clone, PartialEq, Eq, thiserror::Error, miette::Diagnostic,
72)]
73#[serde(tag = "error", content = "message")]
74pub enum CreateAccountError {
75 #[serde(rename = "InvalidHandle")]
76 InvalidHandle(Option<SmolStr>),
77 #[serde(rename = "InvalidPassword")]
78 InvalidPassword(Option<SmolStr>),
79 #[serde(rename = "InvalidInviteCode")]
80 InvalidInviteCode(Option<SmolStr>),
81 #[serde(rename = "HandleNotAvailable")]
82 HandleNotAvailable(Option<SmolStr>),
83 #[serde(rename = "UnsupportedDomain")]
84 UnsupportedDomain(Option<SmolStr>),
85 #[serde(rename = "UnresolvableDid")]
86 UnresolvableDid(Option<SmolStr>),
87 #[serde(rename = "IncompatibleDidDoc")]
88 IncompatibleDidDoc(Option<SmolStr>),
89 #[serde(untagged)]
91 Other {
92 error: SmolStr,
93 message: Option<SmolStr>,
94 },
95}
96
97impl core::fmt::Display for CreateAccountError {
98 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
99 match self {
100 Self::InvalidHandle(msg) => {
101 write!(f, "InvalidHandle")?;
102 if let Some(msg) = msg {
103 write!(f, ": {}", msg)?;
104 }
105 Ok(())
106 }
107 Self::InvalidPassword(msg) => {
108 write!(f, "InvalidPassword")?;
109 if let Some(msg) = msg {
110 write!(f, ": {}", msg)?;
111 }
112 Ok(())
113 }
114 Self::InvalidInviteCode(msg) => {
115 write!(f, "InvalidInviteCode")?;
116 if let Some(msg) = msg {
117 write!(f, ": {}", msg)?;
118 }
119 Ok(())
120 }
121 Self::HandleNotAvailable(msg) => {
122 write!(f, "HandleNotAvailable")?;
123 if let Some(msg) = msg {
124 write!(f, ": {}", msg)?;
125 }
126 Ok(())
127 }
128 Self::UnsupportedDomain(msg) => {
129 write!(f, "UnsupportedDomain")?;
130 if let Some(msg) = msg {
131 write!(f, ": {}", msg)?;
132 }
133 Ok(())
134 }
135 Self::UnresolvableDid(msg) => {
136 write!(f, "UnresolvableDid")?;
137 if let Some(msg) = msg {
138 write!(f, ": {}", msg)?;
139 }
140 Ok(())
141 }
142 Self::IncompatibleDidDoc(msg) => {
143 write!(f, "IncompatibleDidDoc")?;
144 if let Some(msg) = msg {
145 write!(f, ": {}", msg)?;
146 }
147 Ok(())
148 }
149 Self::Other { error, message } => {
150 write!(f, "{}", error)?;
151 if let Some(msg) = message {
152 write!(f, ": {}", msg)?;
153 }
154 Ok(())
155 }
156 }
157 }
158}
159
160pub struct CreateAccountResponse;
164impl jacquard_common::xrpc::XrpcResp for CreateAccountResponse {
165 const NSID: &'static str = "com.atproto.server.createAccount";
166 const ENCODING: &'static str = "application/json";
167 type Output<S: BosStr> = CreateAccountOutput<S>;
168 type Err = CreateAccountError;
169}
170
171impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CreateAccount<S> {
172 const NSID: &'static str = "com.atproto.server.createAccount";
173 const METHOD: jacquard_common::xrpc::XrpcMethod =
174 jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
175 type Response = CreateAccountResponse;
176}
177
178pub struct CreateAccountRequest;
182impl jacquard_common::xrpc::XrpcEndpoint for CreateAccountRequest {
183 const PATH: &'static str = "/xrpc/com.atproto.server.createAccount";
184 const METHOD: jacquard_common::xrpc::XrpcMethod =
185 jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
186 type Request<S: BosStr> = CreateAccount<S>;
187 type Response = CreateAccountResponse;
188}
189
190pub mod create_account_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 Handle;
201 }
202 pub struct Empty(());
204 impl sealed::Sealed for Empty {}
205 impl State for Empty {
206 type Handle = Unset;
207 }
208 pub struct SetHandle<St: State = Empty>(PhantomData<fn() -> St>);
210 impl<St: State> sealed::Sealed for SetHandle<St> {}
211 impl<St: State> State for SetHandle<St> {
212 type Handle = Set<members::handle>;
213 }
214 #[allow(non_camel_case_types)]
216 pub mod members {
217 pub struct handle(());
219 }
220}
221
222pub struct CreateAccountBuilder<St: create_account_state::State, S: BosStr = DefaultStr> {
224 _state: PhantomData<fn() -> St>,
225 _fields: (
226 Option<Did<S>>,
227 Option<S>,
228 Option<Handle<S>>,
229 Option<S>,
230 Option<S>,
231 Option<Data<S>>,
232 Option<S>,
233 Option<S>,
234 Option<S>,
235 ),
236 _type: PhantomData<fn() -> S>,
237}
238
239impl CreateAccount<DefaultStr> {
240 pub fn new() -> CreateAccountBuilder<create_account_state::Empty, DefaultStr> {
242 CreateAccountBuilder::new()
243 }
244}
245
246impl<S: BosStr> CreateAccount<S> {
247 pub fn builder() -> CreateAccountBuilder<create_account_state::Empty, S> {
249 CreateAccountBuilder::builder()
250 }
251}
252
253impl CreateAccountBuilder<create_account_state::Empty, DefaultStr> {
254 pub fn new() -> Self {
256 CreateAccountBuilder {
257 _state: PhantomData,
258 _fields: (None, None, None, None, None, None, None, None, None),
259 _type: PhantomData,
260 }
261 }
262}
263
264impl<S: BosStr> CreateAccountBuilder<create_account_state::Empty, S> {
265 pub fn builder() -> Self {
267 CreateAccountBuilder {
268 _state: PhantomData,
269 _fields: (None, None, None, None, None, None, None, None, None),
270 _type: PhantomData,
271 }
272 }
273}
274
275impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
276 pub fn did(mut self, value: impl Into<Option<Did<S>>>) -> Self {
278 self._fields.0 = value.into();
279 self
280 }
281 pub fn maybe_did(mut self, value: Option<Did<S>>) -> Self {
283 self._fields.0 = value;
284 self
285 }
286}
287
288impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
289 pub fn email(mut self, value: impl Into<Option<S>>) -> Self {
291 self._fields.1 = value.into();
292 self
293 }
294 pub fn maybe_email(mut self, value: Option<S>) -> Self {
296 self._fields.1 = value;
297 self
298 }
299}
300
301impl<St, S: BosStr> CreateAccountBuilder<St, S>
302where
303 St: create_account_state::State,
304 St::Handle: create_account_state::IsUnset,
305{
306 pub fn handle(
308 mut self,
309 value: impl Into<Handle<S>>,
310 ) -> CreateAccountBuilder<create_account_state::SetHandle<St>, S> {
311 self._fields.2 = Option::Some(value.into());
312 CreateAccountBuilder {
313 _state: PhantomData,
314 _fields: self._fields,
315 _type: PhantomData,
316 }
317 }
318}
319
320impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
321 pub fn invite_code(mut self, value: impl Into<Option<S>>) -> Self {
323 self._fields.3 = value.into();
324 self
325 }
326 pub fn maybe_invite_code(mut self, value: Option<S>) -> Self {
328 self._fields.3 = value;
329 self
330 }
331}
332
333impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
334 pub fn password(mut self, value: impl Into<Option<S>>) -> Self {
336 self._fields.4 = value.into();
337 self
338 }
339 pub fn maybe_password(mut self, value: Option<S>) -> Self {
341 self._fields.4 = value;
342 self
343 }
344}
345
346impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
347 pub fn plc_op(mut self, value: impl Into<Option<Data<S>>>) -> Self {
349 self._fields.5 = value.into();
350 self
351 }
352 pub fn maybe_plc_op(mut self, value: Option<Data<S>>) -> Self {
354 self._fields.5 = value;
355 self
356 }
357}
358
359impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
360 pub fn recovery_key(mut self, value: impl Into<Option<S>>) -> Self {
362 self._fields.6 = value.into();
363 self
364 }
365 pub fn maybe_recovery_key(mut self, value: Option<S>) -> Self {
367 self._fields.6 = value;
368 self
369 }
370}
371
372impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
373 pub fn verification_code(mut self, value: impl Into<Option<S>>) -> Self {
375 self._fields.7 = value.into();
376 self
377 }
378 pub fn maybe_verification_code(mut self, value: Option<S>) -> Self {
380 self._fields.7 = value;
381 self
382 }
383}
384
385impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
386 pub fn verification_phone(mut self, value: impl Into<Option<S>>) -> Self {
388 self._fields.8 = value.into();
389 self
390 }
391 pub fn maybe_verification_phone(mut self, value: Option<S>) -> Self {
393 self._fields.8 = value;
394 self
395 }
396}
397
398impl<St, S: BosStr> CreateAccountBuilder<St, S>
399where
400 St: create_account_state::State,
401 St::Handle: create_account_state::IsSet,
402{
403 pub fn build(self) -> CreateAccount<S> {
405 CreateAccount {
406 did: self._fields.0,
407 email: self._fields.1,
408 handle: self._fields.2.unwrap(),
409 invite_code: self._fields.3,
410 password: self._fields.4,
411 plc_op: self._fields.5,
412 recovery_key: self._fields.6,
413 verification_code: self._fields.7,
414 verification_phone: self._fields.8,
415 extra_data: Default::default(),
416 }
417 }
418 pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> CreateAccount<S> {
420 CreateAccount {
421 did: self._fields.0,
422 email: self._fields.1,
423 handle: self._fields.2.unwrap(),
424 invite_code: self._fields.3,
425 password: self._fields.4,
426 plc_op: self._fields.5,
427 recovery_key: self._fields.6,
428 verification_code: self._fields.7,
429 verification_phone: self._fields.8,
430 extra_data: Some(extra_data),
431 }
432 }
433}