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