jacquard_api/place_stream/server/
get_webhook.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14use jacquard_derive::{IntoStatic, lexicon, open_union};
15use serde::{Serialize, Deserialize};
16use crate::place_stream::server::Webhook;
17
18#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
19#[serde(rename_all = "camelCase")]
20pub struct GetWebhook<'a> {
21 #[serde(borrow)]
22 pub id: CowStr<'a>,
23}
24
25
26#[lexicon]
27#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
28#[serde(rename_all = "camelCase")]
29pub struct GetWebhookOutput<'a> {
30 #[serde(borrow)]
31 pub webhook: Webhook<'a>,
32}
33
34
35#[open_union]
36#[derive(
37 Serialize,
38 Deserialize,
39 Debug,
40 Clone,
41 PartialEq,
42 Eq,
43 thiserror::Error,
44 miette::Diagnostic,
45 IntoStatic
46)]
47
48#[serde(tag = "error", content = "message")]
49#[serde(bound(deserialize = "'de: 'a"))]
50pub enum GetWebhookError<'a> {
51 #[serde(rename = "WebhookNotFound")]
53 WebhookNotFound(Option<CowStr<'a>>),
54 #[serde(rename = "Unauthorized")]
56 Unauthorized(Option<CowStr<'a>>),
57}
58
59impl core::fmt::Display for GetWebhookError<'_> {
60 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
61 match self {
62 Self::WebhookNotFound(msg) => {
63 write!(f, "WebhookNotFound")?;
64 if let Some(msg) = msg {
65 write!(f, ": {}", msg)?;
66 }
67 Ok(())
68 }
69 Self::Unauthorized(msg) => {
70 write!(f, "Unauthorized")?;
71 if let Some(msg) = msg {
72 write!(f, ": {}", msg)?;
73 }
74 Ok(())
75 }
76 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
77 }
78 }
79}
80
81pub struct GetWebhookResponse;
83impl jacquard_common::xrpc::XrpcResp for GetWebhookResponse {
84 const NSID: &'static str = "place.stream.server.getWebhook";
85 const ENCODING: &'static str = "application/json";
86 type Output<'de> = GetWebhookOutput<'de>;
87 type Err<'de> = GetWebhookError<'de>;
88}
89
90impl<'a> jacquard_common::xrpc::XrpcRequest for GetWebhook<'a> {
91 const NSID: &'static str = "place.stream.server.getWebhook";
92 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
93 type Response = GetWebhookResponse;
94}
95
96pub struct GetWebhookRequest;
98impl jacquard_common::xrpc::XrpcEndpoint for GetWebhookRequest {
99 const PATH: &'static str = "/xrpc/place.stream.server.getWebhook";
100 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
101 type Request<'de> = GetWebhook<'de>;
102 type Response = GetWebhookResponse;
103}
104
105pub mod get_webhook_state {
106
107 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
108 #[allow(unused)]
109 use ::core::marker::PhantomData;
110 mod sealed {
111 pub trait Sealed {}
112 }
113 pub trait State: sealed::Sealed {
115 type Id;
116 }
117 pub struct Empty(());
119 impl sealed::Sealed for Empty {}
120 impl State for Empty {
121 type Id = Unset;
122 }
123 pub struct SetId<S: State = Empty>(PhantomData<fn() -> S>);
125 impl<S: State> sealed::Sealed for SetId<S> {}
126 impl<S: State> State for SetId<S> {
127 type Id = Set<members::id>;
128 }
129 #[allow(non_camel_case_types)]
131 pub mod members {
132 pub struct id(());
134 }
135}
136
137pub struct GetWebhookBuilder<'a, S: get_webhook_state::State> {
139 _state: PhantomData<fn() -> S>,
140 _fields: (Option<CowStr<'a>>,),
141 _lifetime: PhantomData<&'a ()>,
142}
143
144impl<'a> GetWebhook<'a> {
145 pub fn new() -> GetWebhookBuilder<'a, get_webhook_state::Empty> {
147 GetWebhookBuilder::new()
148 }
149}
150
151impl<'a> GetWebhookBuilder<'a, get_webhook_state::Empty> {
152 pub fn new() -> Self {
154 GetWebhookBuilder {
155 _state: PhantomData,
156 _fields: (None,),
157 _lifetime: PhantomData,
158 }
159 }
160}
161
162impl<'a, S> GetWebhookBuilder<'a, S>
163where
164 S: get_webhook_state::State,
165 S::Id: get_webhook_state::IsUnset,
166{
167 pub fn id(
169 mut self,
170 value: impl Into<CowStr<'a>>,
171 ) -> GetWebhookBuilder<'a, get_webhook_state::SetId<S>> {
172 self._fields.0 = Option::Some(value.into());
173 GetWebhookBuilder {
174 _state: PhantomData,
175 _fields: self._fields,
176 _lifetime: PhantomData,
177 }
178 }
179}
180
181impl<'a, S> GetWebhookBuilder<'a, S>
182where
183 S: get_webhook_state::State,
184 S::Id: get_webhook_state::IsSet,
185{
186 pub fn build(self) -> GetWebhook<'a> {
188 GetWebhook {
189 id: self._fields.0.unwrap(),
190 }
191 }
192}