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