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_derive::{IntoStatic, lexicon, open_union};
18use jacquard_lexicon::lexicon::LexiconDoc;
19use jacquard_lexicon::schema::LexiconSchema;
20
21#[allow(unused_imports)]
22use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
23use serde::{Serialize, Deserialize};
24use crate::com_atproto::label::Label;
25use crate::com_atproto::label::subscribe_labels;
26
27#[lexicon]
28#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
29#[serde(rename_all = "camelCase")]
30pub struct Info<'a> {
31 #[serde(skip_serializing_if = "Option::is_none")]
32 #[serde(borrow)]
33 pub message: Option<CowStr<'a>>,
34 #[serde(borrow)]
35 pub name: InfoName<'a>,
36}
37
38
39#[derive(Debug, Clone, PartialEq, Eq, Hash)]
40pub enum InfoName<'a> {
41 OutdatedCursor,
42 Other(CowStr<'a>),
43}
44
45impl<'a> InfoName<'a> {
46 pub fn as_str(&self) -> &str {
47 match self {
48 Self::OutdatedCursor => "OutdatedCursor",
49 Self::Other(s) => s.as_ref(),
50 }
51 }
52}
53
54impl<'a> From<&'a str> for InfoName<'a> {
55 fn from(s: &'a str) -> Self {
56 match s {
57 "OutdatedCursor" => Self::OutdatedCursor,
58 _ => Self::Other(CowStr::from(s)),
59 }
60 }
61}
62
63impl<'a> From<String> for InfoName<'a> {
64 fn from(s: String) -> Self {
65 match s.as_str() {
66 "OutdatedCursor" => Self::OutdatedCursor,
67 _ => Self::Other(CowStr::from(s)),
68 }
69 }
70}
71
72impl<'a> core::fmt::Display for InfoName<'a> {
73 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
74 write!(f, "{}", self.as_str())
75 }
76}
77
78impl<'a> AsRef<str> for InfoName<'a> {
79 fn as_ref(&self) -> &str {
80 self.as_str()
81 }
82}
83
84impl<'a> serde::Serialize for InfoName<'a> {
85 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
86 where
87 S: serde::Serializer,
88 {
89 serializer.serialize_str(self.as_str())
90 }
91}
92
93impl<'de, 'a> serde::Deserialize<'de> for InfoName<'a>
94where
95 'de: 'a,
96{
97 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
98 where
99 D: serde::Deserializer<'de>,
100 {
101 let s = <&'de str>::deserialize(deserializer)?;
102 Ok(Self::from(s))
103 }
104}
105
106impl<'a> Default for InfoName<'a> {
107 fn default() -> Self {
108 Self::Other(Default::default())
109 }
110}
111
112impl jacquard_common::IntoStatic for InfoName<'_> {
113 type Output = InfoName<'static>;
114 fn into_static(self) -> Self::Output {
115 match self {
116 InfoName::OutdatedCursor => InfoName::OutdatedCursor,
117 InfoName::Other(v) => InfoName::Other(v.into_static()),
118 }
119 }
120}
121
122
123#[lexicon]
124#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
125#[serde(rename_all = "camelCase")]
126pub struct Labels<'a> {
127 #[serde(borrow)]
128 pub labels: Vec<Label<'a>>,
129 pub seq: i64,
130}
131
132
133#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
134#[serde(rename_all = "camelCase")]
135pub struct SubscribeLabels {
136 #[serde(skip_serializing_if = "Option::is_none")]
137 pub cursor: Option<i64>,
138}
139
140
141#[open_union]
142#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
143#[serde(tag = "$type")]
144#[serde(bound(deserialize = "'de: 'a"))]
145pub enum SubscribeLabelsMessage<'a> {
146 #[serde(rename = "#labels")]
147 Labels(Box<subscribe_labels::Labels<'a>>),
148 #[serde(rename = "#info")]
149 Info(Box<subscribe_labels::Info<'a>>),
150}
151
152impl<'a> SubscribeLabelsMessage<'a> {
153 pub fn decode_framed<'de: 'a>(
155 bytes: &'de [u8],
156 ) -> Result<SubscribeLabelsMessage<'a>, jacquard_common::error::DecodeError> {
157 let (header, body) = jacquard_common::xrpc::subscription::parse_event_header(
158 bytes,
159 )?;
160 match header.t.as_str() {
161 "#labels" => {
162 let variant = jacquard_common::deps::codegen::serde_ipld_dagcbor::from_slice(
163 body,
164 )?;
165 Ok(Self::Labels(Box::new(variant)))
166 }
167 "#info" => {
168 let variant = jacquard_common::deps::codegen::serde_ipld_dagcbor::from_slice(
169 body,
170 )?;
171 Ok(Self::Info(Box::new(variant)))
172 }
173 unknown => {
174 Err(
175 jacquard_common::error::DecodeError::UnknownEventType(unknown.into()),
176 )
177 }
178 }
179 }
180}
181
182
183#[open_union]
184#[derive(
185 Serialize,
186 Deserialize,
187 Debug,
188 Clone,
189 PartialEq,
190 Eq,
191 thiserror::Error,
192 miette::Diagnostic,
193 IntoStatic
194)]
195
196#[serde(tag = "error", content = "message")]
197#[serde(bound(deserialize = "'de: 'a"))]
198pub enum SubscribeLabelsError<'a> {
199 #[serde(rename = "FutureCursor")]
200 FutureCursor(Option<CowStr<'a>>),
201}
202
203impl core::fmt::Display for SubscribeLabelsError<'_> {
204 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
205 match self {
206 Self::FutureCursor(msg) => {
207 write!(f, "FutureCursor")?;
208 if let Some(msg) = msg {
209 write!(f, ": {}", msg)?;
210 }
211 Ok(())
212 }
213 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
214 }
215 }
216}
217
218impl<'a> LexiconSchema for Info<'a> {
219 fn nsid() -> &'static str {
220 "com.atproto.label.subscribeLabels"
221 }
222 fn def_name() -> &'static str {
223 "info"
224 }
225 fn lexicon_doc() -> LexiconDoc<'static> {
226 lexicon_doc_com_atproto_label_subscribeLabels()
227 }
228 fn validate(&self) -> Result<(), ConstraintError> {
229 Ok(())
230 }
231}
232
233impl<'a> LexiconSchema for Labels<'a> {
234 fn nsid() -> &'static str {
235 "com.atproto.label.subscribeLabels"
236 }
237 fn def_name() -> &'static str {
238 "labels"
239 }
240 fn lexicon_doc() -> LexiconDoc<'static> {
241 lexicon_doc_com_atproto_label_subscribeLabels()
242 }
243 fn validate(&self) -> Result<(), ConstraintError> {
244 Ok(())
245 }
246}
247
248pub struct SubscribeLabelsStream;
251impl jacquard_common::xrpc::SubscriptionResp for SubscribeLabelsStream {
252 const NSID: &'static str = "com.atproto.label.subscribeLabels";
253 const ENCODING: jacquard_common::xrpc::MessageEncoding = jacquard_common::xrpc::MessageEncoding::DagCbor;
254 type Message<'de> = SubscribeLabelsMessage<'de>;
255 type Error<'de> = SubscribeLabelsError<'de>;
256 fn decode_message<'de>(
257 bytes: &'de [u8],
258 ) -> Result<Self::Message<'de>, jacquard_common::error::DecodeError> {
259 SubscribeLabelsMessage::decode_framed(bytes)
260 }
261}
262
263impl jacquard_common::xrpc::XrpcSubscription for SubscribeLabels {
264 const NSID: &'static str = "com.atproto.label.subscribeLabels";
265 const ENCODING: jacquard_common::xrpc::MessageEncoding = jacquard_common::xrpc::MessageEncoding::DagCbor;
266 type Stream = SubscribeLabelsStream;
267}
268
269pub struct SubscribeLabelsEndpoint;
270impl jacquard_common::xrpc::SubscriptionEndpoint for SubscribeLabelsEndpoint {
271 const PATH: &'static str = "/xrpc/com.atproto.label.subscribeLabels";
272 const ENCODING: jacquard_common::xrpc::MessageEncoding = jacquard_common::xrpc::MessageEncoding::DagCbor;
273 type Params<'de> = SubscribeLabels;
274 type Stream = SubscribeLabelsStream;
275}
276
277fn lexicon_doc_com_atproto_label_subscribeLabels() -> LexiconDoc<'static> {
278 #[allow(unused_imports)]
279 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
280 use jacquard_lexicon::lexicon::*;
281 use alloc::collections::BTreeMap;
282 LexiconDoc {
283 lexicon: Lexicon::Lexicon1,
284 id: CowStr::new_static("com.atproto.label.subscribeLabels"),
285 defs: {
286 let mut map = BTreeMap::new();
287 map.insert(
288 SmolStr::new_static("info"),
289 LexUserType::Object(LexObject {
290 required: Some(vec![SmolStr::new_static("name")]),
291 properties: {
292 #[allow(unused_mut)]
293 let mut map = BTreeMap::new();
294 map.insert(
295 SmolStr::new_static("message"),
296 LexObjectProperty::String(LexString { ..Default::default() }),
297 );
298 map.insert(
299 SmolStr::new_static("name"),
300 LexObjectProperty::String(LexString { ..Default::default() }),
301 );
302 map
303 },
304 ..Default::default()
305 }),
306 );
307 map.insert(
308 SmolStr::new_static("labels"),
309 LexUserType::Object(LexObject {
310 required: Some(
311 vec![SmolStr::new_static("seq"), SmolStr::new_static("labels")],
312 ),
313 properties: {
314 #[allow(unused_mut)]
315 let mut map = BTreeMap::new();
316 map.insert(
317 SmolStr::new_static("labels"),
318 LexObjectProperty::Array(LexArray {
319 items: LexArrayItem::Ref(LexRef {
320 r#ref: CowStr::new_static("com.atproto.label.defs#label"),
321 ..Default::default()
322 }),
323 ..Default::default()
324 }),
325 );
326 map.insert(
327 SmolStr::new_static("seq"),
328 LexObjectProperty::Integer(LexInteger {
329 ..Default::default()
330 }),
331 );
332 map
333 },
334 ..Default::default()
335 }),
336 );
337 map.insert(
338 SmolStr::new_static("main"),
339 LexUserType::XrpcSubscription(LexXrpcSubscription {
340 parameters: Some(
341 LexXrpcSubscriptionParameter::Params(LexXrpcParameters {
342 properties: {
343 #[allow(unused_mut)]
344 let mut map = BTreeMap::new();
345 map.insert(
346 SmolStr::new_static("cursor"),
347 LexXrpcParametersProperty::Integer(LexInteger {
348 ..Default::default()
349 }),
350 );
351 map
352 },
353 ..Default::default()
354 }),
355 ),
356 ..Default::default()
357 }),
358 );
359 map
360 },
361 ..Default::default()
362 }
363}
364
365pub mod labels_state {
366
367 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
368 #[allow(unused)]
369 use ::core::marker::PhantomData;
370 mod sealed {
371 pub trait Sealed {}
372 }
373 pub trait State: sealed::Sealed {
375 type Seq;
376 type Labels;
377 }
378 pub struct Empty(());
380 impl sealed::Sealed for Empty {}
381 impl State for Empty {
382 type Seq = Unset;
383 type Labels = Unset;
384 }
385 pub struct SetSeq<S: State = Empty>(PhantomData<fn() -> S>);
387 impl<S: State> sealed::Sealed for SetSeq<S> {}
388 impl<S: State> State for SetSeq<S> {
389 type Seq = Set<members::seq>;
390 type Labels = S::Labels;
391 }
392 pub struct SetLabels<S: State = Empty>(PhantomData<fn() -> S>);
394 impl<S: State> sealed::Sealed for SetLabels<S> {}
395 impl<S: State> State for SetLabels<S> {
396 type Seq = S::Seq;
397 type Labels = Set<members::labels>;
398 }
399 #[allow(non_camel_case_types)]
401 pub mod members {
402 pub struct seq(());
404 pub struct labels(());
406 }
407}
408
409pub struct LabelsBuilder<'a, S: labels_state::State> {
411 _state: PhantomData<fn() -> S>,
412 _fields: (Option<Vec<Label<'a>>>, Option<i64>),
413 _lifetime: PhantomData<&'a ()>,
414}
415
416impl<'a> Labels<'a> {
417 pub fn new() -> LabelsBuilder<'a, labels_state::Empty> {
419 LabelsBuilder::new()
420 }
421}
422
423impl<'a> LabelsBuilder<'a, labels_state::Empty> {
424 pub fn new() -> Self {
426 LabelsBuilder {
427 _state: PhantomData,
428 _fields: (None, None),
429 _lifetime: PhantomData,
430 }
431 }
432}
433
434impl<'a, S> LabelsBuilder<'a, S>
435where
436 S: labels_state::State,
437 S::Labels: labels_state::IsUnset,
438{
439 pub fn labels(
441 mut self,
442 value: impl Into<Vec<Label<'a>>>,
443 ) -> LabelsBuilder<'a, labels_state::SetLabels<S>> {
444 self._fields.0 = Option::Some(value.into());
445 LabelsBuilder {
446 _state: PhantomData,
447 _fields: self._fields,
448 _lifetime: PhantomData,
449 }
450 }
451}
452
453impl<'a, S> LabelsBuilder<'a, S>
454where
455 S: labels_state::State,
456 S::Seq: labels_state::IsUnset,
457{
458 pub fn seq(
460 mut self,
461 value: impl Into<i64>,
462 ) -> LabelsBuilder<'a, labels_state::SetSeq<S>> {
463 self._fields.1 = Option::Some(value.into());
464 LabelsBuilder {
465 _state: PhantomData,
466 _fields: self._fields,
467 _lifetime: PhantomData,
468 }
469 }
470}
471
472impl<'a, S> LabelsBuilder<'a, S>
473where
474 S: labels_state::State,
475 S::Seq: labels_state::IsSet,
476 S::Labels: labels_state::IsSet,
477{
478 pub fn build(self) -> Labels<'a> {
480 Labels {
481 labels: self._fields.0.unwrap(),
482 seq: self._fields.1.unwrap(),
483 extra_data: Default::default(),
484 }
485 }
486 pub fn build_with_data(
488 self,
489 extra_data: BTreeMap<
490 jacquard_common::deps::smol_str::SmolStr,
491 jacquard_common::types::value::Data<'a>,
492 >,
493 ) -> Labels<'a> {
494 Labels {
495 labels: self._fields.0.unwrap(),
496 seq: self._fields.1.unwrap(),
497 extra_data: Some(extra_data),
498 }
499 }
500}
501
502pub mod subscribe_labels_state {
503
504 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
505 #[allow(unused)]
506 use ::core::marker::PhantomData;
507 mod sealed {
508 pub trait Sealed {}
509 }
510 pub trait State: sealed::Sealed {}
512 pub struct Empty(());
514 impl sealed::Sealed for Empty {}
515 impl State for Empty {}
516 #[allow(non_camel_case_types)]
518 pub mod members {}
519}
520
521pub struct SubscribeLabelsBuilder<S: subscribe_labels_state::State> {
523 _state: PhantomData<fn() -> S>,
524 _fields: (Option<i64>,),
525}
526
527impl SubscribeLabels {
528 pub fn new() -> SubscribeLabelsBuilder<subscribe_labels_state::Empty> {
530 SubscribeLabelsBuilder::new()
531 }
532}
533
534impl SubscribeLabelsBuilder<subscribe_labels_state::Empty> {
535 pub fn new() -> Self {
537 SubscribeLabelsBuilder {
538 _state: PhantomData,
539 _fields: (None,),
540 }
541 }
542}
543
544impl<S: subscribe_labels_state::State> SubscribeLabelsBuilder<S> {
545 pub fn cursor(mut self, value: impl Into<Option<i64>>) -> Self {
547 self._fields.0 = value.into();
548 self
549 }
550 pub fn maybe_cursor(mut self, value: Option<i64>) -> Self {
552 self._fields.0 = value;
553 self
554 }
555}
556
557impl<S> SubscribeLabelsBuilder<S>
558where
559 S: subscribe_labels_state::State,
560{
561 pub fn build(self) -> SubscribeLabels {
563 SubscribeLabels {
564 cursor: self._fields.0,
565 }
566 }
567}