1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::{CowStr, BosStr, 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::{Handle, Datetime};
19use jacquard_common::types::value::Data;
20use jacquard_derive::{IntoStatic, open_union};
21use jacquard_lexicon::lexicon::LexiconDoc;
22use jacquard_lexicon::schema::LexiconSchema;
23
24#[allow(unused_imports)]
25use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
26use serde::{Serialize, Deserialize};
27use crate::com_atproto::temp::check_handle_availability;
28
29#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
30#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
31pub struct CheckHandleAvailability<S: BosStr = DefaultStr> {
32 #[serde(skip_serializing_if = "Option::is_none")]
33 pub birth_date: Option<Datetime>,
34 #[serde(skip_serializing_if = "Option::is_none")]
35 pub email: Option<S>,
36 pub handle: Handle<S>,
37}
38
39
40#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
41#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
42pub struct CheckHandleAvailabilityOutput<S: BosStr = DefaultStr> {
43 pub handle: Handle<S>,
45 pub result: CheckHandleAvailabilityOutputResult<S>,
46 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
47 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
48}
49
50
51#[open_union]
52#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
53#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
54pub enum CheckHandleAvailabilityOutputResult<S: BosStr = DefaultStr> {
55 #[serde(rename = "com.atproto.temp.checkHandleAvailability#resultAvailable")]
56 ResultAvailable(Box<check_handle_availability::ResultAvailable<S>>),
57 #[serde(rename = "com.atproto.temp.checkHandleAvailability#resultUnavailable")]
58 ResultUnavailable(Box<check_handle_availability::ResultUnavailable<S>>),
59}
60
61
62#[derive(
63 Serialize,
64 Deserialize,
65 Debug,
66 Clone,
67 PartialEq,
68 Eq,
69 thiserror::Error,
70 miette::Diagnostic
71)]
72
73#[serde(tag = "error", content = "message")]
74pub enum CheckHandleAvailabilityError {
75 #[serde(rename = "InvalidEmail")]
77 InvalidEmail(Option<SmolStr>),
78 #[serde(untagged)]
80 Other { error: SmolStr, message: Option<SmolStr> },
81}
82
83impl core::fmt::Display for CheckHandleAvailabilityError {
84 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
85 match self {
86 Self::InvalidEmail(msg) => {
87 write!(f, "InvalidEmail")?;
88 if let Some(msg) = msg {
89 write!(f, ": {}", msg)?;
90 }
91 Ok(())
92 }
93 Self::Other { error, message } => {
94 write!(f, "{}", error)?;
95 if let Some(msg) = message {
96 write!(f, ": {}", msg)?;
97 }
98 Ok(())
99 }
100 }
101 }
102}
103
104#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
107#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
108pub struct ResultAvailable<S: BosStr = DefaultStr> {
109 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
110 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
111}
112
113#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
116#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
117pub struct ResultUnavailable<S: BosStr = DefaultStr> {
118 pub suggestions: Vec<check_handle_availability::Suggestion<S>>,
120 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
121 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
122}
123
124
125#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
126#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
127pub struct Suggestion<S: BosStr = DefaultStr> {
128 pub handle: Handle<S>,
129 pub method: S,
131 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
132 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
133}
134
135pub struct CheckHandleAvailabilityResponse;
139impl jacquard_common::xrpc::XrpcResp for CheckHandleAvailabilityResponse {
140 const NSID: &'static str = "com.atproto.temp.checkHandleAvailability";
141 const ENCODING: &'static str = "application/json";
142 type Output<S: BosStr> = CheckHandleAvailabilityOutput<S>;
143 type Err = CheckHandleAvailabilityError;
144}
145
146impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CheckHandleAvailability<S> {
147 const NSID: &'static str = "com.atproto.temp.checkHandleAvailability";
148 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
149 type Response = CheckHandleAvailabilityResponse;
150}
151
152pub struct CheckHandleAvailabilityRequest;
156impl jacquard_common::xrpc::XrpcEndpoint for CheckHandleAvailabilityRequest {
157 const PATH: &'static str = "/xrpc/com.atproto.temp.checkHandleAvailability";
158 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
159 type Request<S: BosStr> = CheckHandleAvailability<S>;
160 type Response = CheckHandleAvailabilityResponse;
161}
162
163impl<S: BosStr> LexiconSchema for ResultAvailable<S> {
164 fn nsid() -> &'static str {
165 "com.atproto.temp.checkHandleAvailability"
166 }
167 fn def_name() -> &'static str {
168 "resultAvailable"
169 }
170 fn lexicon_doc() -> LexiconDoc<'static> {
171 lexicon_doc_com_atproto_temp_checkHandleAvailability()
172 }
173 fn validate(&self) -> Result<(), ConstraintError> {
174 Ok(())
175 }
176}
177
178impl<S: BosStr> LexiconSchema for ResultUnavailable<S> {
179 fn nsid() -> &'static str {
180 "com.atproto.temp.checkHandleAvailability"
181 }
182 fn def_name() -> &'static str {
183 "resultUnavailable"
184 }
185 fn lexicon_doc() -> LexiconDoc<'static> {
186 lexicon_doc_com_atproto_temp_checkHandleAvailability()
187 }
188 fn validate(&self) -> Result<(), ConstraintError> {
189 Ok(())
190 }
191}
192
193impl<S: BosStr> LexiconSchema for Suggestion<S> {
194 fn nsid() -> &'static str {
195 "com.atproto.temp.checkHandleAvailability"
196 }
197 fn def_name() -> &'static str {
198 "suggestion"
199 }
200 fn lexicon_doc() -> LexiconDoc<'static> {
201 lexicon_doc_com_atproto_temp_checkHandleAvailability()
202 }
203 fn validate(&self) -> Result<(), ConstraintError> {
204 Ok(())
205 }
206}
207
208pub mod check_handle_availability_state {
209
210 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
211 #[allow(unused)]
212 use ::core::marker::PhantomData;
213 mod sealed {
214 pub trait Sealed {}
215 }
216 pub trait State: sealed::Sealed {
218 type Handle;
219 }
220 pub struct Empty(());
222 impl sealed::Sealed for Empty {}
223 impl State for Empty {
224 type Handle = Unset;
225 }
226 pub struct SetHandle<St: State = Empty>(PhantomData<fn() -> St>);
228 impl<St: State> sealed::Sealed for SetHandle<St> {}
229 impl<St: State> State for SetHandle<St> {
230 type Handle = Set<members::handle>;
231 }
232 #[allow(non_camel_case_types)]
234 pub mod members {
235 pub struct handle(());
237 }
238}
239
240pub struct CheckHandleAvailabilityBuilder<
242 St: check_handle_availability_state::State,
243 S: BosStr = DefaultStr,
244> {
245 _state: PhantomData<fn() -> St>,
246 _fields: (Option<Datetime>, Option<S>, Option<Handle<S>>),
247 _type: PhantomData<fn() -> S>,
248}
249
250impl CheckHandleAvailability<DefaultStr> {
251 pub fn new() -> CheckHandleAvailabilityBuilder<
253 check_handle_availability_state::Empty,
254 DefaultStr,
255 > {
256 CheckHandleAvailabilityBuilder::new()
257 }
258}
259
260impl<S: BosStr> CheckHandleAvailability<S> {
261 pub fn builder() -> CheckHandleAvailabilityBuilder<
263 check_handle_availability_state::Empty,
264 S,
265 > {
266 CheckHandleAvailabilityBuilder::builder()
267 }
268}
269
270impl CheckHandleAvailabilityBuilder<check_handle_availability_state::Empty, DefaultStr> {
271 pub fn new() -> Self {
273 CheckHandleAvailabilityBuilder {
274 _state: PhantomData,
275 _fields: (None, None, None),
276 _type: PhantomData,
277 }
278 }
279}
280
281impl<
282 S: BosStr,
283> CheckHandleAvailabilityBuilder<check_handle_availability_state::Empty, S> {
284 pub fn builder() -> Self {
286 CheckHandleAvailabilityBuilder {
287 _state: PhantomData,
288 _fields: (None, None, None),
289 _type: PhantomData,
290 }
291 }
292}
293
294impl<
295 St: check_handle_availability_state::State,
296 S: BosStr,
297> CheckHandleAvailabilityBuilder<St, S> {
298 pub fn birth_date(mut self, value: impl Into<Option<Datetime>>) -> Self {
300 self._fields.0 = value.into();
301 self
302 }
303 pub fn maybe_birth_date(mut self, value: Option<Datetime>) -> Self {
305 self._fields.0 = value;
306 self
307 }
308}
309
310impl<
311 St: check_handle_availability_state::State,
312 S: BosStr,
313> CheckHandleAvailabilityBuilder<St, S> {
314 pub fn email(mut self, value: impl Into<Option<S>>) -> Self {
316 self._fields.1 = value.into();
317 self
318 }
319 pub fn maybe_email(mut self, value: Option<S>) -> Self {
321 self._fields.1 = value;
322 self
323 }
324}
325
326impl<St, S: BosStr> CheckHandleAvailabilityBuilder<St, S>
327where
328 St: check_handle_availability_state::State,
329 St::Handle: check_handle_availability_state::IsUnset,
330{
331 pub fn handle(
333 mut self,
334 value: impl Into<Handle<S>>,
335 ) -> CheckHandleAvailabilityBuilder<
336 check_handle_availability_state::SetHandle<St>,
337 S,
338 > {
339 self._fields.2 = Option::Some(value.into());
340 CheckHandleAvailabilityBuilder {
341 _state: PhantomData,
342 _fields: self._fields,
343 _type: PhantomData,
344 }
345 }
346}
347
348impl<St, S: BosStr> CheckHandleAvailabilityBuilder<St, S>
349where
350 St: check_handle_availability_state::State,
351 St::Handle: check_handle_availability_state::IsSet,
352{
353 pub fn build(self) -> CheckHandleAvailability<S> {
355 CheckHandleAvailability {
356 birth_date: self._fields.0,
357 email: self._fields.1,
358 handle: self._fields.2.unwrap(),
359 }
360 }
361}
362
363fn lexicon_doc_com_atproto_temp_checkHandleAvailability() -> LexiconDoc<'static> {
364 #[allow(unused_imports)]
365 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
366 use jacquard_lexicon::lexicon::*;
367 use alloc::collections::BTreeMap;
368 LexiconDoc {
369 lexicon: Lexicon::Lexicon1,
370 id: CowStr::new_static("com.atproto.temp.checkHandleAvailability"),
371 defs: {
372 let mut map = BTreeMap::new();
373 map.insert(
374 SmolStr::new_static("main"),
375 LexUserType::XrpcQuery(LexXrpcQuery {
376 parameters: Some(
377 LexXrpcQueryParameter::Params(LexXrpcParameters {
378 required: Some(vec![SmolStr::new_static("handle")]),
379 properties: {
380 #[allow(unused_mut)]
381 let mut map = BTreeMap::new();
382 map.insert(
383 SmolStr::new_static("birthDate"),
384 LexXrpcParametersProperty::String(LexString {
385 description: Some(
386 CowStr::new_static(
387 "User-provided birth date. Might be used to build handle suggestions.",
388 ),
389 ),
390 format: Some(LexStringFormat::Datetime),
391 ..Default::default()
392 }),
393 );
394 map.insert(
395 SmolStr::new_static("email"),
396 LexXrpcParametersProperty::String(LexString {
397 description: Some(
398 CowStr::new_static(
399 "User-provided email. Might be used to build handle suggestions.",
400 ),
401 ),
402 ..Default::default()
403 }),
404 );
405 map.insert(
406 SmolStr::new_static("handle"),
407 LexXrpcParametersProperty::String(LexString {
408 description: Some(
409 CowStr::new_static(
410 "Tentative handle. Will be checked for availability or used to build handle suggestions.",
411 ),
412 ),
413 format: Some(LexStringFormat::Handle),
414 ..Default::default()
415 }),
416 );
417 map
418 },
419 ..Default::default()
420 }),
421 ),
422 ..Default::default()
423 }),
424 );
425 map.insert(
426 SmolStr::new_static("resultAvailable"),
427 LexUserType::Object(LexObject {
428 description: Some(
429 CowStr::new_static("Indicates the provided handle is available."),
430 ),
431 properties: {
432 #[allow(unused_mut)]
433 let mut map = BTreeMap::new();
434 map
435 },
436 ..Default::default()
437 }),
438 );
439 map.insert(
440 SmolStr::new_static("resultUnavailable"),
441 LexUserType::Object(LexObject {
442 description: Some(
443 CowStr::new_static(
444 "Indicates the provided handle is unavailable and gives suggestions of available handles.",
445 ),
446 ),
447 required: Some(vec![SmolStr::new_static("suggestions")]),
448 properties: {
449 #[allow(unused_mut)]
450 let mut map = BTreeMap::new();
451 map.insert(
452 SmolStr::new_static("suggestions"),
453 LexObjectProperty::Array(LexArray {
454 description: Some(
455 CowStr::new_static(
456 "List of suggested handles based on the provided inputs.",
457 ),
458 ),
459 items: LexArrayItem::Ref(LexRef {
460 r#ref: CowStr::new_static("#suggestion"),
461 ..Default::default()
462 }),
463 ..Default::default()
464 }),
465 );
466 map
467 },
468 ..Default::default()
469 }),
470 );
471 map.insert(
472 SmolStr::new_static("suggestion"),
473 LexUserType::Object(LexObject {
474 required: Some(
475 vec![
476 SmolStr::new_static("handle"), SmolStr::new_static("method")
477 ],
478 ),
479 properties: {
480 #[allow(unused_mut)]
481 let mut map = BTreeMap::new();
482 map.insert(
483 SmolStr::new_static("handle"),
484 LexObjectProperty::String(LexString {
485 format: Some(LexStringFormat::Handle),
486 ..Default::default()
487 }),
488 );
489 map.insert(
490 SmolStr::new_static("method"),
491 LexObjectProperty::String(LexString {
492 description: Some(
493 CowStr::new_static(
494 "Method used to build this suggestion. Should be considered opaque to clients. Can be used for metrics.",
495 ),
496 ),
497 ..Default::default()
498 }),
499 );
500 map
501 },
502 ..Default::default()
503 }),
504 );
505 map
506 },
507 ..Default::default()
508 }
509}
510
511pub mod result_unavailable_state {
512
513 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
514 #[allow(unused)]
515 use ::core::marker::PhantomData;
516 mod sealed {
517 pub trait Sealed {}
518 }
519 pub trait State: sealed::Sealed {
521 type Suggestions;
522 }
523 pub struct Empty(());
525 impl sealed::Sealed for Empty {}
526 impl State for Empty {
527 type Suggestions = Unset;
528 }
529 pub struct SetSuggestions<St: State = Empty>(PhantomData<fn() -> St>);
531 impl<St: State> sealed::Sealed for SetSuggestions<St> {}
532 impl<St: State> State for SetSuggestions<St> {
533 type Suggestions = Set<members::suggestions>;
534 }
535 #[allow(non_camel_case_types)]
537 pub mod members {
538 pub struct suggestions(());
540 }
541}
542
543pub struct ResultUnavailableBuilder<
545 St: result_unavailable_state::State,
546 S: BosStr = DefaultStr,
547> {
548 _state: PhantomData<fn() -> St>,
549 _fields: (Option<Vec<check_handle_availability::Suggestion<S>>>,),
550 _type: PhantomData<fn() -> S>,
551}
552
553impl ResultUnavailable<DefaultStr> {
554 pub fn new() -> ResultUnavailableBuilder<
556 result_unavailable_state::Empty,
557 DefaultStr,
558 > {
559 ResultUnavailableBuilder::new()
560 }
561}
562
563impl<S: BosStr> ResultUnavailable<S> {
564 pub fn builder() -> ResultUnavailableBuilder<result_unavailable_state::Empty, S> {
566 ResultUnavailableBuilder::builder()
567 }
568}
569
570impl ResultUnavailableBuilder<result_unavailable_state::Empty, DefaultStr> {
571 pub fn new() -> Self {
573 ResultUnavailableBuilder {
574 _state: PhantomData,
575 _fields: (None,),
576 _type: PhantomData,
577 }
578 }
579}
580
581impl<S: BosStr> ResultUnavailableBuilder<result_unavailable_state::Empty, S> {
582 pub fn builder() -> Self {
584 ResultUnavailableBuilder {
585 _state: PhantomData,
586 _fields: (None,),
587 _type: PhantomData,
588 }
589 }
590}
591
592impl<St, S: BosStr> ResultUnavailableBuilder<St, S>
593where
594 St: result_unavailable_state::State,
595 St::Suggestions: result_unavailable_state::IsUnset,
596{
597 pub fn suggestions(
599 mut self,
600 value: impl Into<Vec<check_handle_availability::Suggestion<S>>>,
601 ) -> ResultUnavailableBuilder<result_unavailable_state::SetSuggestions<St>, S> {
602 self._fields.0 = Option::Some(value.into());
603 ResultUnavailableBuilder {
604 _state: PhantomData,
605 _fields: self._fields,
606 _type: PhantomData,
607 }
608 }
609}
610
611impl<St, S: BosStr> ResultUnavailableBuilder<St, S>
612where
613 St: result_unavailable_state::State,
614 St::Suggestions: result_unavailable_state::IsSet,
615{
616 pub fn build(self) -> ResultUnavailable<S> {
618 ResultUnavailable {
619 suggestions: self._fields.0.unwrap(),
620 extra_data: Default::default(),
621 }
622 }
623 pub fn build_with_data(
625 self,
626 extra_data: BTreeMap<SmolStr, Data<S>>,
627 ) -> ResultUnavailable<S> {
628 ResultUnavailable {
629 suggestions: self._fields.0.unwrap(),
630 extra_data: Some(extra_data),
631 }
632 }
633}
634
635pub mod suggestion_state {
636
637 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
638 #[allow(unused)]
639 use ::core::marker::PhantomData;
640 mod sealed {
641 pub trait Sealed {}
642 }
643 pub trait State: sealed::Sealed {
645 type Handle;
646 type Method;
647 }
648 pub struct Empty(());
650 impl sealed::Sealed for Empty {}
651 impl State for Empty {
652 type Handle = Unset;
653 type Method = Unset;
654 }
655 pub struct SetHandle<St: State = Empty>(PhantomData<fn() -> St>);
657 impl<St: State> sealed::Sealed for SetHandle<St> {}
658 impl<St: State> State for SetHandle<St> {
659 type Handle = Set<members::handle>;
660 type Method = St::Method;
661 }
662 pub struct SetMethod<St: State = Empty>(PhantomData<fn() -> St>);
664 impl<St: State> sealed::Sealed for SetMethod<St> {}
665 impl<St: State> State for SetMethod<St> {
666 type Handle = St::Handle;
667 type Method = Set<members::method>;
668 }
669 #[allow(non_camel_case_types)]
671 pub mod members {
672 pub struct handle(());
674 pub struct method(());
676 }
677}
678
679pub struct SuggestionBuilder<St: suggestion_state::State, S: BosStr = DefaultStr> {
681 _state: PhantomData<fn() -> St>,
682 _fields: (Option<Handle<S>>, Option<S>),
683 _type: PhantomData<fn() -> S>,
684}
685
686impl Suggestion<DefaultStr> {
687 pub fn new() -> SuggestionBuilder<suggestion_state::Empty, DefaultStr> {
689 SuggestionBuilder::new()
690 }
691}
692
693impl<S: BosStr> Suggestion<S> {
694 pub fn builder() -> SuggestionBuilder<suggestion_state::Empty, S> {
696 SuggestionBuilder::builder()
697 }
698}
699
700impl SuggestionBuilder<suggestion_state::Empty, DefaultStr> {
701 pub fn new() -> Self {
703 SuggestionBuilder {
704 _state: PhantomData,
705 _fields: (None, None),
706 _type: PhantomData,
707 }
708 }
709}
710
711impl<S: BosStr> SuggestionBuilder<suggestion_state::Empty, S> {
712 pub fn builder() -> Self {
714 SuggestionBuilder {
715 _state: PhantomData,
716 _fields: (None, None),
717 _type: PhantomData,
718 }
719 }
720}
721
722impl<St, S: BosStr> SuggestionBuilder<St, S>
723where
724 St: suggestion_state::State,
725 St::Handle: suggestion_state::IsUnset,
726{
727 pub fn handle(
729 mut self,
730 value: impl Into<Handle<S>>,
731 ) -> SuggestionBuilder<suggestion_state::SetHandle<St>, S> {
732 self._fields.0 = Option::Some(value.into());
733 SuggestionBuilder {
734 _state: PhantomData,
735 _fields: self._fields,
736 _type: PhantomData,
737 }
738 }
739}
740
741impl<St, S: BosStr> SuggestionBuilder<St, S>
742where
743 St: suggestion_state::State,
744 St::Method: suggestion_state::IsUnset,
745{
746 pub fn method(
748 mut self,
749 value: impl Into<S>,
750 ) -> SuggestionBuilder<suggestion_state::SetMethod<St>, S> {
751 self._fields.1 = Option::Some(value.into());
752 SuggestionBuilder {
753 _state: PhantomData,
754 _fields: self._fields,
755 _type: PhantomData,
756 }
757 }
758}
759
760impl<St, S: BosStr> SuggestionBuilder<St, S>
761where
762 St: suggestion_state::State,
763 St::Handle: suggestion_state::IsSet,
764 St::Method: suggestion_state::IsSet,
765{
766 pub fn build(self) -> Suggestion<S> {
768 Suggestion {
769 handle: self._fields.0.unwrap(),
770 method: self._fields.1.unwrap(),
771 extra_data: Default::default(),
772 }
773 }
774 pub fn build_with_data(
776 self,
777 extra_data: BTreeMap<SmolStr, Data<S>>,
778 ) -> Suggestion<S> {
779 Suggestion {
780 handle: self._fields.0.unwrap(),
781 method: self._fields.1.unwrap(),
782 extra_data: Some(extra_data),
783 }
784 }
785}