Skip to main content

jacquard_api/place_stream/server/
create_webhook.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: place.stream.server.createWebhook
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::UriValue;
15use jacquard_derive::{IntoStatic, lexicon, open_union};
16use serde::{Serialize, Deserialize};
17use crate::place_stream::server::RewriteRule;
18use crate::place_stream::server::Webhook;
19
20#[lexicon]
21#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
22#[serde(rename_all = "camelCase")]
23pub struct CreateWebhook<'a> {
24    ///Whether this webhook should be active upon creation.  Defaults to `false`.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    #[serde(default = "_default_create_webhook_active")]
27    pub active: Option<bool>,
28    ///A description of what this webhook is used for.
29    #[serde(skip_serializing_if = "Option::is_none")]
30    #[serde(borrow)]
31    pub description: Option<CowStr<'a>>,
32    ///The types of events this webhook should receive.
33    #[serde(borrow)]
34    pub events: Vec<CowStr<'a>>,
35    ///Words to filter out from chat messages. Messages containing any of these words will not be forwarded.
36    #[serde(skip_serializing_if = "Option::is_none")]
37    #[serde(borrow)]
38    pub mute_words: Option<Vec<CowStr<'a>>>,
39    ///A user-friendly name for this webhook.
40    #[serde(skip_serializing_if = "Option::is_none")]
41    #[serde(borrow)]
42    pub name: Option<CowStr<'a>>,
43    ///Text to prepend to webhook messages.
44    #[serde(skip_serializing_if = "Option::is_none")]
45    #[serde(borrow)]
46    pub prefix: Option<CowStr<'a>>,
47    ///Text replacement rules for webhook messages.
48    #[serde(skip_serializing_if = "Option::is_none")]
49    #[serde(borrow)]
50    pub rewrite: Option<Vec<RewriteRule<'a>>>,
51    ///Text to append to webhook messages.
52    #[serde(skip_serializing_if = "Option::is_none")]
53    #[serde(borrow)]
54    pub suffix: Option<CowStr<'a>>,
55    ///The webhook URL where events will be sent.
56    #[serde(borrow)]
57    pub url: UriValue<'a>,
58}
59
60
61#[lexicon]
62#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
63#[serde(rename_all = "camelCase")]
64pub struct CreateWebhookOutput<'a> {
65    #[serde(borrow)]
66    pub webhook: Webhook<'a>,
67}
68
69
70#[open_union]
71#[derive(
72    Serialize,
73    Deserialize,
74    Debug,
75    Clone,
76    PartialEq,
77    Eq,
78    thiserror::Error,
79    miette::Diagnostic,
80    IntoStatic
81)]
82
83#[serde(tag = "error", content = "message")]
84#[serde(bound(deserialize = "'de: 'a"))]
85pub enum CreateWebhookError<'a> {
86    /// The provided webhook URL is invalid or unreachable.
87    #[serde(rename = "InvalidUrl")]
88    InvalidUrl(Option<CowStr<'a>>),
89    /// A webhook with this URL already exists for this user.
90    #[serde(rename = "DuplicateWebhook")]
91    DuplicateWebhook(Option<CowStr<'a>>),
92    /// The user has reached their maximum number of webhooks.
93    #[serde(rename = "TooManyWebhooks")]
94    TooManyWebhooks(Option<CowStr<'a>>),
95}
96
97impl core::fmt::Display for CreateWebhookError<'_> {
98    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
99        match self {
100            Self::InvalidUrl(msg) => {
101                write!(f, "InvalidUrl")?;
102                if let Some(msg) = msg {
103                    write!(f, ": {}", msg)?;
104                }
105                Ok(())
106            }
107            Self::DuplicateWebhook(msg) => {
108                write!(f, "DuplicateWebhook")?;
109                if let Some(msg) = msg {
110                    write!(f, ": {}", msg)?;
111                }
112                Ok(())
113            }
114            Self::TooManyWebhooks(msg) => {
115                write!(f, "TooManyWebhooks")?;
116                if let Some(msg) = msg {
117                    write!(f, ": {}", msg)?;
118                }
119                Ok(())
120            }
121            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
122        }
123    }
124}
125
126/// Response type for place.stream.server.createWebhook
127pub struct CreateWebhookResponse;
128impl jacquard_common::xrpc::XrpcResp for CreateWebhookResponse {
129    const NSID: &'static str = "place.stream.server.createWebhook";
130    const ENCODING: &'static str = "application/json";
131    type Output<'de> = CreateWebhookOutput<'de>;
132    type Err<'de> = CreateWebhookError<'de>;
133}
134
135impl<'a> jacquard_common::xrpc::XrpcRequest for CreateWebhook<'a> {
136    const NSID: &'static str = "place.stream.server.createWebhook";
137    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
138        "application/json",
139    );
140    type Response = CreateWebhookResponse;
141}
142
143/// Endpoint type for place.stream.server.createWebhook
144pub struct CreateWebhookRequest;
145impl jacquard_common::xrpc::XrpcEndpoint for CreateWebhookRequest {
146    const PATH: &'static str = "/xrpc/place.stream.server.createWebhook";
147    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
148        "application/json",
149    );
150    type Request<'de> = CreateWebhook<'de>;
151    type Response = CreateWebhookResponse;
152}
153
154fn _default_create_webhook_active() -> Option<bool> {
155    Some(false)
156}
157
158pub mod create_webhook_state {
159
160    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
161    #[allow(unused)]
162    use ::core::marker::PhantomData;
163    mod sealed {
164        pub trait Sealed {}
165    }
166    /// State trait tracking which required fields have been set
167    pub trait State: sealed::Sealed {
168        type Events;
169        type Url;
170    }
171    /// Empty state - all required fields are unset
172    pub struct Empty(());
173    impl sealed::Sealed for Empty {}
174    impl State for Empty {
175        type Events = Unset;
176        type Url = Unset;
177    }
178    ///State transition - sets the `events` field to Set
179    pub struct SetEvents<S: State = Empty>(PhantomData<fn() -> S>);
180    impl<S: State> sealed::Sealed for SetEvents<S> {}
181    impl<S: State> State for SetEvents<S> {
182        type Events = Set<members::events>;
183        type Url = S::Url;
184    }
185    ///State transition - sets the `url` field to Set
186    pub struct SetUrl<S: State = Empty>(PhantomData<fn() -> S>);
187    impl<S: State> sealed::Sealed for SetUrl<S> {}
188    impl<S: State> State for SetUrl<S> {
189        type Events = S::Events;
190        type Url = Set<members::url>;
191    }
192    /// Marker types for field names
193    #[allow(non_camel_case_types)]
194    pub mod members {
195        ///Marker type for the `events` field
196        pub struct events(());
197        ///Marker type for the `url` field
198        pub struct url(());
199    }
200}
201
202/// Builder for constructing an instance of this type
203pub struct CreateWebhookBuilder<'a, S: create_webhook_state::State> {
204    _state: PhantomData<fn() -> S>,
205    _fields: (
206        Option<bool>,
207        Option<CowStr<'a>>,
208        Option<Vec<CowStr<'a>>>,
209        Option<Vec<CowStr<'a>>>,
210        Option<CowStr<'a>>,
211        Option<CowStr<'a>>,
212        Option<Vec<RewriteRule<'a>>>,
213        Option<CowStr<'a>>,
214        Option<UriValue<'a>>,
215    ),
216    _lifetime: PhantomData<&'a ()>,
217}
218
219impl<'a> CreateWebhook<'a> {
220    /// Create a new builder for this type
221    pub fn new() -> CreateWebhookBuilder<'a, create_webhook_state::Empty> {
222        CreateWebhookBuilder::new()
223    }
224}
225
226impl<'a> CreateWebhookBuilder<'a, create_webhook_state::Empty> {
227    /// Create a new builder with all fields unset
228    pub fn new() -> Self {
229        CreateWebhookBuilder {
230            _state: PhantomData,
231            _fields: (None, None, None, None, None, None, None, None, None),
232            _lifetime: PhantomData,
233        }
234    }
235}
236
237impl<'a, S: create_webhook_state::State> CreateWebhookBuilder<'a, S> {
238    /// Set the `active` field (optional)
239    pub fn active(mut self, value: impl Into<Option<bool>>) -> Self {
240        self._fields.0 = value.into();
241        self
242    }
243    /// Set the `active` field to an Option value (optional)
244    pub fn maybe_active(mut self, value: Option<bool>) -> Self {
245        self._fields.0 = value;
246        self
247    }
248}
249
250impl<'a, S: create_webhook_state::State> CreateWebhookBuilder<'a, S> {
251    /// Set the `description` field (optional)
252    pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
253        self._fields.1 = value.into();
254        self
255    }
256    /// Set the `description` field to an Option value (optional)
257    pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
258        self._fields.1 = value;
259        self
260    }
261}
262
263impl<'a, S> CreateWebhookBuilder<'a, S>
264where
265    S: create_webhook_state::State,
266    S::Events: create_webhook_state::IsUnset,
267{
268    /// Set the `events` field (required)
269    pub fn events(
270        mut self,
271        value: impl Into<Vec<CowStr<'a>>>,
272    ) -> CreateWebhookBuilder<'a, create_webhook_state::SetEvents<S>> {
273        self._fields.2 = Option::Some(value.into());
274        CreateWebhookBuilder {
275            _state: PhantomData,
276            _fields: self._fields,
277            _lifetime: PhantomData,
278        }
279    }
280}
281
282impl<'a, S: create_webhook_state::State> CreateWebhookBuilder<'a, S> {
283    /// Set the `muteWords` field (optional)
284    pub fn mute_words(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> Self {
285        self._fields.3 = value.into();
286        self
287    }
288    /// Set the `muteWords` field to an Option value (optional)
289    pub fn maybe_mute_words(mut self, value: Option<Vec<CowStr<'a>>>) -> Self {
290        self._fields.3 = value;
291        self
292    }
293}
294
295impl<'a, S: create_webhook_state::State> CreateWebhookBuilder<'a, S> {
296    /// Set the `name` field (optional)
297    pub fn name(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
298        self._fields.4 = value.into();
299        self
300    }
301    /// Set the `name` field to an Option value (optional)
302    pub fn maybe_name(mut self, value: Option<CowStr<'a>>) -> Self {
303        self._fields.4 = value;
304        self
305    }
306}
307
308impl<'a, S: create_webhook_state::State> CreateWebhookBuilder<'a, S> {
309    /// Set the `prefix` field (optional)
310    pub fn prefix(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
311        self._fields.5 = value.into();
312        self
313    }
314    /// Set the `prefix` field to an Option value (optional)
315    pub fn maybe_prefix(mut self, value: Option<CowStr<'a>>) -> Self {
316        self._fields.5 = value;
317        self
318    }
319}
320
321impl<'a, S: create_webhook_state::State> CreateWebhookBuilder<'a, S> {
322    /// Set the `rewrite` field (optional)
323    pub fn rewrite(mut self, value: impl Into<Option<Vec<RewriteRule<'a>>>>) -> Self {
324        self._fields.6 = value.into();
325        self
326    }
327    /// Set the `rewrite` field to an Option value (optional)
328    pub fn maybe_rewrite(mut self, value: Option<Vec<RewriteRule<'a>>>) -> Self {
329        self._fields.6 = value;
330        self
331    }
332}
333
334impl<'a, S: create_webhook_state::State> CreateWebhookBuilder<'a, S> {
335    /// Set the `suffix` field (optional)
336    pub fn suffix(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
337        self._fields.7 = value.into();
338        self
339    }
340    /// Set the `suffix` field to an Option value (optional)
341    pub fn maybe_suffix(mut self, value: Option<CowStr<'a>>) -> Self {
342        self._fields.7 = value;
343        self
344    }
345}
346
347impl<'a, S> CreateWebhookBuilder<'a, S>
348where
349    S: create_webhook_state::State,
350    S::Url: create_webhook_state::IsUnset,
351{
352    /// Set the `url` field (required)
353    pub fn url(
354        mut self,
355        value: impl Into<UriValue<'a>>,
356    ) -> CreateWebhookBuilder<'a, create_webhook_state::SetUrl<S>> {
357        self._fields.8 = Option::Some(value.into());
358        CreateWebhookBuilder {
359            _state: PhantomData,
360            _fields: self._fields,
361            _lifetime: PhantomData,
362        }
363    }
364}
365
366impl<'a, S> CreateWebhookBuilder<'a, S>
367where
368    S: create_webhook_state::State,
369    S::Events: create_webhook_state::IsSet,
370    S::Url: create_webhook_state::IsSet,
371{
372    /// Build the final struct
373    pub fn build(self) -> CreateWebhook<'a> {
374        CreateWebhook {
375            active: self._fields.0.or_else(|| Some(false)),
376            description: self._fields.1,
377            events: self._fields.2.unwrap(),
378            mute_words: self._fields.3,
379            name: self._fields.4,
380            prefix: self._fields.5,
381            rewrite: self._fields.6,
382            suffix: self._fields.7,
383            url: self._fields.8.unwrap(),
384            extra_data: Default::default(),
385        }
386    }
387    /// Build the final struct with custom extra_data
388    pub fn build_with_data(
389        self,
390        extra_data: BTreeMap<
391            jacquard_common::deps::smol_str::SmolStr,
392            jacquard_common::types::value::Data<'a>,
393        >,
394    ) -> CreateWebhook<'a> {
395        CreateWebhook {
396            active: self._fields.0.or_else(|| Some(false)),
397            description: self._fields.1,
398            events: self._fields.2.unwrap(),
399            mute_words: self._fields.3,
400            name: self._fields.4,
401            prefix: self._fields.5,
402            rewrite: self._fields.6,
403            suffix: self._fields.7,
404            url: self._fields.8.unwrap(),
405            extra_data: Some(extra_data),
406        }
407    }
408}