Skip to main content

jacquard_api/place_stream/moderation/
create_gate.rs

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