Skip to main content

jacquard_api/app_bsky/feed/
get_post_thread.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: app.bsky.feed.getPostThread
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
11use crate::app_bsky::feed::BlockedPost;
12use crate::app_bsky::feed::NotFoundPost;
13use crate::app_bsky::feed::ThreadViewPost;
14use crate::app_bsky::feed::ThreadgateView;
15#[allow(unused_imports)]
16use core::marker::PhantomData;
17use jacquard_common::deps::smol_str::SmolStr;
18use jacquard_common::types::string::AtUri;
19use jacquard_common::types::value::Data;
20use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
21use jacquard_derive::{IntoStatic, open_union};
22use serde::{Deserialize, Serialize};
23
24#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
25#[serde(
26    rename_all = "camelCase",
27    bound(deserialize = "S: Deserialize<'de> + BosStr")
28)]
29pub struct GetPostThread<S: BosStr = DefaultStr> {
30    /// Defaults to `6`. Min: 0. Max: 1000.
31    #[serde(default = "_default_depth")]
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub depth: Option<i64>,
34    /// Defaults to `80`. Min: 0. Max: 1000.
35    #[serde(default = "_default_parent_height")]
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub parent_height: Option<i64>,
38    pub uri: AtUri<S>,
39}
40
41#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
42#[serde(
43    rename_all = "camelCase",
44    bound(deserialize = "S: Deserialize<'de> + BosStr")
45)]
46pub struct GetPostThreadOutput<S: BosStr = DefaultStr> {
47    pub thread: GetPostThreadOutputThread<S>,
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub threadgate: Option<ThreadgateView<S>>,
50    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
51    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
52}
53
54#[open_union]
55#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
56#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
57pub enum GetPostThreadOutputThread<S: BosStr = DefaultStr> {
58    #[serde(rename = "app.bsky.feed.defs#threadViewPost")]
59    ThreadViewPost(Box<ThreadViewPost<S>>),
60    #[serde(rename = "app.bsky.feed.defs#notFoundPost")]
61    NotFoundPost(Box<NotFoundPost<S>>),
62    #[serde(rename = "app.bsky.feed.defs#blockedPost")]
63    BlockedPost(Box<BlockedPost<S>>),
64}
65
66#[derive(
67    Serialize, Deserialize, Debug, Clone, PartialEq, Eq, thiserror::Error, miette::Diagnostic,
68)]
69#[serde(tag = "error", content = "message")]
70pub enum GetPostThreadError {
71    #[serde(rename = "NotFound")]
72    NotFound(Option<SmolStr>),
73    /// Catch-all for unknown error codes.
74    #[serde(untagged)]
75    Other {
76        error: SmolStr,
77        message: Option<SmolStr>,
78    },
79}
80
81impl core::fmt::Display for GetPostThreadError {
82    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
83        match self {
84            Self::NotFound(msg) => {
85                write!(f, "NotFound")?;
86                if let Some(msg) = msg {
87                    write!(f, ": {}", msg)?;
88                }
89                Ok(())
90            }
91            Self::Other { error, message } => {
92                write!(f, "{}", error)?;
93                if let Some(msg) = message {
94                    write!(f, ": {}", msg)?;
95                }
96                Ok(())
97            }
98        }
99    }
100}
101
102/** Response marker for the `app.bsky.feed.getPostThread` query.
103
104Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `GetPostThreadOutput<S>` for this endpoint.*/
105pub struct GetPostThreadResponse;
106impl jacquard_common::xrpc::XrpcResp for GetPostThreadResponse {
107    const NSID: &'static str = "app.bsky.feed.getPostThread";
108    const ENCODING: &'static str = "application/json";
109    type Output<S: BosStr> = GetPostThreadOutput<S>;
110    type Err = GetPostThreadError;
111}
112
113impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetPostThread<S> {
114    const NSID: &'static str = "app.bsky.feed.getPostThread";
115    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
116    type Response = GetPostThreadResponse;
117}
118
119/** Endpoint marker for the `app.bsky.feed.getPostThread` query.
120
121Path: `/xrpc/app.bsky.feed.getPostThread`. The request payload type is `GetPostThread<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
122pub struct GetPostThreadRequest;
123impl jacquard_common::xrpc::XrpcEndpoint for GetPostThreadRequest {
124    const PATH: &'static str = "/xrpc/app.bsky.feed.getPostThread";
125    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
126    type Request<S: BosStr> = GetPostThread<S>;
127    type Response = GetPostThreadResponse;
128}
129
130fn _default_depth() -> Option<i64> {
131    Some(6i64)
132}
133
134fn _default_parent_height() -> Option<i64> {
135    Some(80i64)
136}
137
138pub mod get_post_thread_state {
139
140    pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
141    #[allow(unused)]
142    use ::core::marker::PhantomData;
143    mod sealed {
144        pub trait Sealed {}
145    }
146    /// State trait tracking which required fields have been set
147    pub trait State: sealed::Sealed {
148        type Uri;
149    }
150    /// Empty state - all required fields are unset
151    pub struct Empty(());
152    impl sealed::Sealed for Empty {}
153    impl State for Empty {
154        type Uri = Unset;
155    }
156    ///State transition - sets the `uri` field to Set
157    pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
158    impl<St: State> sealed::Sealed for SetUri<St> {}
159    impl<St: State> State for SetUri<St> {
160        type Uri = Set<members::uri>;
161    }
162    /// Marker types for field names
163    #[allow(non_camel_case_types)]
164    pub mod members {
165        ///Marker type for the `uri` field
166        pub struct uri(());
167    }
168}
169
170/// Builder for constructing an instance of this type.
171pub struct GetPostThreadBuilder<St: get_post_thread_state::State, S: BosStr = DefaultStr> {
172    _state: PhantomData<fn() -> St>,
173    _fields: (Option<i64>, Option<i64>, Option<AtUri<S>>),
174    _type: PhantomData<fn() -> S>,
175}
176
177impl GetPostThread<DefaultStr> {
178    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
179    pub fn new() -> GetPostThreadBuilder<get_post_thread_state::Empty, DefaultStr> {
180        GetPostThreadBuilder::new()
181    }
182}
183
184impl<S: BosStr> GetPostThread<S> {
185    /// Create a new builder for this type
186    pub fn builder() -> GetPostThreadBuilder<get_post_thread_state::Empty, S> {
187        GetPostThreadBuilder::builder()
188    }
189}
190
191impl GetPostThreadBuilder<get_post_thread_state::Empty, DefaultStr> {
192    /// Create a new builder with all fields unset, using the default string type, if needed
193    pub fn new() -> Self {
194        GetPostThreadBuilder {
195            _state: PhantomData,
196            _fields: (None, None, None),
197            _type: PhantomData,
198        }
199    }
200}
201
202impl<S: BosStr> GetPostThreadBuilder<get_post_thread_state::Empty, S> {
203    /// Create a new builder with all fields unset
204    pub fn builder() -> Self {
205        GetPostThreadBuilder {
206            _state: PhantomData,
207            _fields: (None, None, None),
208            _type: PhantomData,
209        }
210    }
211}
212
213impl<St: get_post_thread_state::State, S: BosStr> GetPostThreadBuilder<St, S> {
214    /// Set the `depth` field (optional)
215    pub fn depth(mut self, value: impl Into<Option<i64>>) -> Self {
216        self._fields.0 = value.into();
217        self
218    }
219    /// Set the `depth` field to an Option value (optional)
220    pub fn maybe_depth(mut self, value: Option<i64>) -> Self {
221        self._fields.0 = value;
222        self
223    }
224}
225
226impl<St: get_post_thread_state::State, S: BosStr> GetPostThreadBuilder<St, S> {
227    /// Set the `parentHeight` field (optional)
228    pub fn parent_height(mut self, value: impl Into<Option<i64>>) -> Self {
229        self._fields.1 = value.into();
230        self
231    }
232    /// Set the `parentHeight` field to an Option value (optional)
233    pub fn maybe_parent_height(mut self, value: Option<i64>) -> Self {
234        self._fields.1 = value;
235        self
236    }
237}
238
239impl<St, S: BosStr> GetPostThreadBuilder<St, S>
240where
241    St: get_post_thread_state::State,
242    St::Uri: get_post_thread_state::IsUnset,
243{
244    /// Set the `uri` field (required)
245    pub fn uri(
246        mut self,
247        value: impl Into<AtUri<S>>,
248    ) -> GetPostThreadBuilder<get_post_thread_state::SetUri<St>, S> {
249        self._fields.2 = Option::Some(value.into());
250        GetPostThreadBuilder {
251            _state: PhantomData,
252            _fields: self._fields,
253            _type: PhantomData,
254        }
255    }
256}
257
258impl<St, S: BosStr> GetPostThreadBuilder<St, S>
259where
260    St: get_post_thread_state::State,
261    St::Uri: get_post_thread_state::IsSet,
262{
263    /// Build the final struct.
264    pub fn build(self) -> GetPostThread<S> {
265        GetPostThread {
266            depth: self._fields.0,
267            parent_height: self._fields.1,
268            uri: self._fields.2.unwrap(),
269        }
270    }
271}