Skip to main content

jacquard_api/place_stream/moderation/
delete_block.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: place.stream.moderation.deleteBlock
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;
14use jacquard_common::types::string::{Did, AtUri};
15use jacquard_derive::{IntoStatic, lexicon, open_union};
16use serde::{Serialize, Deserialize};
17
18#[lexicon]
19#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
20#[serde(rename_all = "camelCase")]
21pub struct DeleteBlock<'a> {
22    ///The AT-URI of the block record to delete.
23    #[serde(borrow)]
24    pub block_uri: AtUri<'a>,
25    ///The DID of the streamer.
26    #[serde(borrow)]
27    pub streamer: Did<'a>,
28}
29
30
31#[lexicon]
32#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
33#[serde(rename_all = "camelCase")]
34pub struct DeleteBlockOutput<'a> {}
35
36#[open_union]
37#[derive(
38    Serialize,
39    Deserialize,
40    Debug,
41    Clone,
42    PartialEq,
43    Eq,
44    thiserror::Error,
45    miette::Diagnostic,
46    IntoStatic
47)]
48
49#[serde(tag = "error", content = "message")]
50#[serde(bound(deserialize = "'de: 'a"))]
51pub enum DeleteBlockError<'a> {
52    /// The request lacks valid authentication credentials.
53    #[serde(rename = "Unauthorized")]
54    Unauthorized(Option<CowStr<'a>>),
55    /// The caller does not have permission to delete blocks for this streamer.
56    #[serde(rename = "Forbidden")]
57    Forbidden(Option<CowStr<'a>>),
58    /// The streamer's OAuth session could not be found or is invalid.
59    #[serde(rename = "SessionNotFound")]
60    SessionNotFound(Option<CowStr<'a>>),
61}
62
63impl core::fmt::Display for DeleteBlockError<'_> {
64    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65        match self {
66            Self::Unauthorized(msg) => {
67                write!(f, "Unauthorized")?;
68                if let Some(msg) = msg {
69                    write!(f, ": {}", msg)?;
70                }
71                Ok(())
72            }
73            Self::Forbidden(msg) => {
74                write!(f, "Forbidden")?;
75                if let Some(msg) = msg {
76                    write!(f, ": {}", msg)?;
77                }
78                Ok(())
79            }
80            Self::SessionNotFound(msg) => {
81                write!(f, "SessionNotFound")?;
82                if let Some(msg) = msg {
83                    write!(f, ": {}", msg)?;
84                }
85                Ok(())
86            }
87            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
88        }
89    }
90}
91
92/// Response type for place.stream.moderation.deleteBlock
93pub struct DeleteBlockResponse;
94impl jacquard_common::xrpc::XrpcResp for DeleteBlockResponse {
95    const NSID: &'static str = "place.stream.moderation.deleteBlock";
96    const ENCODING: &'static str = "application/json";
97    type Output<'de> = DeleteBlockOutput<'de>;
98    type Err<'de> = DeleteBlockError<'de>;
99}
100
101impl<'a> jacquard_common::xrpc::XrpcRequest for DeleteBlock<'a> {
102    const NSID: &'static str = "place.stream.moderation.deleteBlock";
103    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
104        "application/json",
105    );
106    type Response = DeleteBlockResponse;
107}
108
109/// Endpoint type for place.stream.moderation.deleteBlock
110pub struct DeleteBlockRequest;
111impl jacquard_common::xrpc::XrpcEndpoint for DeleteBlockRequest {
112    const PATH: &'static str = "/xrpc/place.stream.moderation.deleteBlock";
113    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
114        "application/json",
115    );
116    type Request<'de> = DeleteBlock<'de>;
117    type Response = DeleteBlockResponse;
118}
119
120pub mod delete_block_state {
121
122    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
123    #[allow(unused)]
124    use ::core::marker::PhantomData;
125    mod sealed {
126        pub trait Sealed {}
127    }
128    /// State trait tracking which required fields have been set
129    pub trait State: sealed::Sealed {
130        type Streamer;
131        type BlockUri;
132    }
133    /// Empty state - all required fields are unset
134    pub struct Empty(());
135    impl sealed::Sealed for Empty {}
136    impl State for Empty {
137        type Streamer = Unset;
138        type BlockUri = Unset;
139    }
140    ///State transition - sets the `streamer` field to Set
141    pub struct SetStreamer<S: State = Empty>(PhantomData<fn() -> S>);
142    impl<S: State> sealed::Sealed for SetStreamer<S> {}
143    impl<S: State> State for SetStreamer<S> {
144        type Streamer = Set<members::streamer>;
145        type BlockUri = S::BlockUri;
146    }
147    ///State transition - sets the `block_uri` field to Set
148    pub struct SetBlockUri<S: State = Empty>(PhantomData<fn() -> S>);
149    impl<S: State> sealed::Sealed for SetBlockUri<S> {}
150    impl<S: State> State for SetBlockUri<S> {
151        type Streamer = S::Streamer;
152        type BlockUri = Set<members::block_uri>;
153    }
154    /// Marker types for field names
155    #[allow(non_camel_case_types)]
156    pub mod members {
157        ///Marker type for the `streamer` field
158        pub struct streamer(());
159        ///Marker type for the `block_uri` field
160        pub struct block_uri(());
161    }
162}
163
164/// Builder for constructing an instance of this type
165pub struct DeleteBlockBuilder<'a, S: delete_block_state::State> {
166    _state: PhantomData<fn() -> S>,
167    _fields: (Option<AtUri<'a>>, Option<Did<'a>>),
168    _lifetime: PhantomData<&'a ()>,
169}
170
171impl<'a> DeleteBlock<'a> {
172    /// Create a new builder for this type
173    pub fn new() -> DeleteBlockBuilder<'a, delete_block_state::Empty> {
174        DeleteBlockBuilder::new()
175    }
176}
177
178impl<'a> DeleteBlockBuilder<'a, delete_block_state::Empty> {
179    /// Create a new builder with all fields unset
180    pub fn new() -> Self {
181        DeleteBlockBuilder {
182            _state: PhantomData,
183            _fields: (None, None),
184            _lifetime: PhantomData,
185        }
186    }
187}
188
189impl<'a, S> DeleteBlockBuilder<'a, S>
190where
191    S: delete_block_state::State,
192    S::BlockUri: delete_block_state::IsUnset,
193{
194    /// Set the `blockUri` field (required)
195    pub fn block_uri(
196        mut self,
197        value: impl Into<AtUri<'a>>,
198    ) -> DeleteBlockBuilder<'a, delete_block_state::SetBlockUri<S>> {
199        self._fields.0 = Option::Some(value.into());
200        DeleteBlockBuilder {
201            _state: PhantomData,
202            _fields: self._fields,
203            _lifetime: PhantomData,
204        }
205    }
206}
207
208impl<'a, S> DeleteBlockBuilder<'a, S>
209where
210    S: delete_block_state::State,
211    S::Streamer: delete_block_state::IsUnset,
212{
213    /// Set the `streamer` field (required)
214    pub fn streamer(
215        mut self,
216        value: impl Into<Did<'a>>,
217    ) -> DeleteBlockBuilder<'a, delete_block_state::SetStreamer<S>> {
218        self._fields.1 = Option::Some(value.into());
219        DeleteBlockBuilder {
220            _state: PhantomData,
221            _fields: self._fields,
222            _lifetime: PhantomData,
223        }
224    }
225}
226
227impl<'a, S> DeleteBlockBuilder<'a, S>
228where
229    S: delete_block_state::State,
230    S::Streamer: delete_block_state::IsSet,
231    S::BlockUri: delete_block_state::IsSet,
232{
233    /// Build the final struct
234    pub fn build(self) -> DeleteBlock<'a> {
235        DeleteBlock {
236            block_uri: self._fields.0.unwrap(),
237            streamer: self._fields.1.unwrap(),
238            extra_data: Default::default(),
239        }
240    }
241    /// Build the final struct with custom extra_data
242    pub fn build_with_data(
243        self,
244        extra_data: BTreeMap<
245            jacquard_common::deps::smol_str::SmolStr,
246            jacquard_common::types::value::Data<'a>,
247        >,
248    ) -> DeleteBlock<'a> {
249        DeleteBlock {
250            block_uri: self._fields.0.unwrap(),
251            streamer: self._fields.1.unwrap(),
252            extra_data: Some(extra_data),
253        }
254    }
255}