Skip to main content

jacquard_api/place_stream/moderation/
create_block.rs

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