Skip to main content

jacquard_api/app_bsky/draft/
create_draft.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: app.bsky.draft.createDraft
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
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
14use jacquard_common::deps::smol_str::SmolStr;
15use jacquard_common::types::value::Data;
16use jacquard_derive::{IntoStatic, open_union};
17use serde::{Serialize, Deserialize};
18use crate::app_bsky::draft::Draft;
19
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
21#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
22pub struct CreateDraft<S: BosStr = DefaultStr> {
23    pub draft: Draft<S>,
24    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
25    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
26}
27
28
29#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
30#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
31pub struct CreateDraftOutput<S: BosStr = DefaultStr> {
32    ///The ID of the created draft.
33    pub id: S,
34    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
35    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
36}
37
38
39#[derive(
40    Serialize,
41    Deserialize,
42    Debug,
43    Clone,
44    PartialEq,
45    Eq,
46    thiserror::Error,
47    miette::Diagnostic
48)]
49
50#[serde(tag = "error", content = "message")]
51pub enum CreateDraftError {
52    /// Trying to insert a new draft when the limit was already reached.
53    #[serde(rename = "DraftLimitReached")]
54    DraftLimitReached(Option<SmolStr>),
55    /// Catch-all for unknown error codes.
56    #[serde(untagged)]
57    Other { error: SmolStr, message: Option<SmolStr> },
58}
59
60impl core::fmt::Display for CreateDraftError {
61    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
62        match self {
63            Self::DraftLimitReached(msg) => {
64                write!(f, "DraftLimitReached")?;
65                if let Some(msg) = msg {
66                    write!(f, ": {}", msg)?;
67                }
68                Ok(())
69            }
70            Self::Other { error, message } => {
71                write!(f, "{}", error)?;
72                if let Some(msg) = message {
73                    write!(f, ": {}", msg)?;
74                }
75                Ok(())
76            }
77        }
78    }
79}
80
81/** Response marker for the `app.bsky.draft.createDraft` procedure.
82
83Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `CreateDraftOutput<S>` for this endpoint.*/
84pub struct CreateDraftResponse;
85impl jacquard_common::xrpc::XrpcResp for CreateDraftResponse {
86    const NSID: &'static str = "app.bsky.draft.createDraft";
87    const ENCODING: &'static str = "application/json";
88    type Output<S: BosStr> = CreateDraftOutput<S>;
89    type Err = CreateDraftError;
90}
91
92impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CreateDraft<S> {
93    const NSID: &'static str = "app.bsky.draft.createDraft";
94    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
95        "application/json",
96    );
97    type Response = CreateDraftResponse;
98}
99
100/** Endpoint marker for the `app.bsky.draft.createDraft` procedure.
101
102Path: `/xrpc/app.bsky.draft.createDraft`. The request payload type is `CreateDraft<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
103pub struct CreateDraftRequest;
104impl jacquard_common::xrpc::XrpcEndpoint for CreateDraftRequest {
105    const PATH: &'static str = "/xrpc/app.bsky.draft.createDraft";
106    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
107        "application/json",
108    );
109    type Request<S: BosStr> = CreateDraft<S>;
110    type Response = CreateDraftResponse;
111}
112
113pub mod create_draft_state {
114
115    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
116    #[allow(unused)]
117    use ::core::marker::PhantomData;
118    mod sealed {
119        pub trait Sealed {}
120    }
121    /// State trait tracking which required fields have been set
122    pub trait State: sealed::Sealed {
123        type Draft;
124    }
125    /// Empty state - all required fields are unset
126    pub struct Empty(());
127    impl sealed::Sealed for Empty {}
128    impl State for Empty {
129        type Draft = Unset;
130    }
131    ///State transition - sets the `draft` field to Set
132    pub struct SetDraft<St: State = Empty>(PhantomData<fn() -> St>);
133    impl<St: State> sealed::Sealed for SetDraft<St> {}
134    impl<St: State> State for SetDraft<St> {
135        type Draft = Set<members::draft>;
136    }
137    /// Marker types for field names
138    #[allow(non_camel_case_types)]
139    pub mod members {
140        ///Marker type for the `draft` field
141        pub struct draft(());
142    }
143}
144
145/// Builder for constructing an instance of this type.
146pub struct CreateDraftBuilder<St: create_draft_state::State, S: BosStr = DefaultStr> {
147    _state: PhantomData<fn() -> St>,
148    _fields: (Option<Draft<S>>,),
149    _type: PhantomData<fn() -> S>,
150}
151
152impl CreateDraft<DefaultStr> {
153    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
154    pub fn new() -> CreateDraftBuilder<create_draft_state::Empty, DefaultStr> {
155        CreateDraftBuilder::new()
156    }
157}
158
159impl<S: BosStr> CreateDraft<S> {
160    /// Create a new builder for this type
161    pub fn builder() -> CreateDraftBuilder<create_draft_state::Empty, S> {
162        CreateDraftBuilder::builder()
163    }
164}
165
166impl CreateDraftBuilder<create_draft_state::Empty, DefaultStr> {
167    /// Create a new builder with all fields unset, using the default string type, if needed
168    pub fn new() -> Self {
169        CreateDraftBuilder {
170            _state: PhantomData,
171            _fields: (None,),
172            _type: PhantomData,
173        }
174    }
175}
176
177impl<S: BosStr> CreateDraftBuilder<create_draft_state::Empty, S> {
178    /// Create a new builder with all fields unset
179    pub fn builder() -> Self {
180        CreateDraftBuilder {
181            _state: PhantomData,
182            _fields: (None,),
183            _type: PhantomData,
184        }
185    }
186}
187
188impl<St, S: BosStr> CreateDraftBuilder<St, S>
189where
190    St: create_draft_state::State,
191    St::Draft: create_draft_state::IsUnset,
192{
193    /// Set the `draft` field (required)
194    pub fn draft(
195        mut self,
196        value: impl Into<Draft<S>>,
197    ) -> CreateDraftBuilder<create_draft_state::SetDraft<St>, S> {
198        self._fields.0 = Option::Some(value.into());
199        CreateDraftBuilder {
200            _state: PhantomData,
201            _fields: self._fields,
202            _type: PhantomData,
203        }
204    }
205}
206
207impl<St, S: BosStr> CreateDraftBuilder<St, S>
208where
209    St: create_draft_state::State,
210    St::Draft: create_draft_state::IsSet,
211{
212    /// Build the final struct.
213    pub fn build(self) -> CreateDraft<S> {
214        CreateDraft {
215            draft: self._fields.0.unwrap(),
216            extra_data: Default::default(),
217        }
218    }
219    /// Build the final struct with custom extra_data.
220    pub fn build_with_data(
221        self,
222        extra_data: BTreeMap<SmolStr, Data<S>>,
223    ) -> CreateDraft<S> {
224        CreateDraft {
225            draft: self._fields.0.unwrap(),
226            extra_data: Some(extra_data),
227        }
228    }
229}