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