jacquard_api/chat_bsky/group/
create_join_link.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
14use jacquard_common::deps::smol_str::SmolStr;
15use jacquard_common::types::value::Data;
16use jacquard_derive::{IntoStatic, open_union};
17use serde::{Serialize, Deserialize};
18use crate::chat_bsky::group::JoinLinkView;
19use crate::chat_bsky::group::JoinRule;
20
21#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
22#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
23pub struct CreateJoinLink<S: BosStr = DefaultStr> {
24 pub convo_id: S,
25 pub join_rule: JoinRule<S>,
26 #[serde(skip_serializing_if = "Option::is_none")]
28 #[serde(default = "_default_create_join_link_require_approval")]
29 pub require_approval: Option<bool>,
30 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
31 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
32}
33
34
35#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
36#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
37pub struct CreateJoinLinkOutput<S: BosStr = DefaultStr> {
38 pub join_link: JoinLinkView<S>,
39 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
40 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
41}
42
43
44#[derive(
45 Serialize,
46 Deserialize,
47 Debug,
48 Clone,
49 PartialEq,
50 Eq,
51 thiserror::Error,
52 miette::Diagnostic
53)]
54
55#[serde(tag = "error", content = "message")]
56pub enum CreateJoinLinkError {
57 #[serde(rename = "EnabledJoinLinkAlreadyExists")]
58 EnabledJoinLinkAlreadyExists(Option<SmolStr>),
59 #[serde(rename = "InvalidConvo")]
60 InvalidConvo(Option<SmolStr>),
61 #[serde(rename = "InsufficientRole")]
62 InsufficientRole(Option<SmolStr>),
63 #[serde(untagged)]
65 Other { error: SmolStr, message: Option<SmolStr> },
66}
67
68impl core::fmt::Display for CreateJoinLinkError {
69 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
70 match self {
71 Self::EnabledJoinLinkAlreadyExists(msg) => {
72 write!(f, "EnabledJoinLinkAlreadyExists")?;
73 if let Some(msg) = msg {
74 write!(f, ": {}", msg)?;
75 }
76 Ok(())
77 }
78 Self::InvalidConvo(msg) => {
79 write!(f, "InvalidConvo")?;
80 if let Some(msg) = msg {
81 write!(f, ": {}", msg)?;
82 }
83 Ok(())
84 }
85 Self::InsufficientRole(msg) => {
86 write!(f, "InsufficientRole")?;
87 if let Some(msg) = msg {
88 write!(f, ": {}", msg)?;
89 }
90 Ok(())
91 }
92 Self::Other { error, message } => {
93 write!(f, "{}", error)?;
94 if let Some(msg) = message {
95 write!(f, ": {}", msg)?;
96 }
97 Ok(())
98 }
99 }
100 }
101}
102
103pub struct CreateJoinLinkResponse;
107impl jacquard_common::xrpc::XrpcResp for CreateJoinLinkResponse {
108 const NSID: &'static str = "chat.bsky.group.createJoinLink";
109 const ENCODING: &'static str = "application/json";
110 type Output<S: BosStr> = CreateJoinLinkOutput<S>;
111 type Err = CreateJoinLinkError;
112}
113
114impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CreateJoinLink<S> {
115 const NSID: &'static str = "chat.bsky.group.createJoinLink";
116 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
117 "application/json",
118 );
119 type Response = CreateJoinLinkResponse;
120}
121
122pub struct CreateJoinLinkRequest;
126impl jacquard_common::xrpc::XrpcEndpoint for CreateJoinLinkRequest {
127 const PATH: &'static str = "/xrpc/chat.bsky.group.createJoinLink";
128 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
129 "application/json",
130 );
131 type Request<S: BosStr> = CreateJoinLink<S>;
132 type Response = CreateJoinLinkResponse;
133}
134
135fn _default_create_join_link_require_approval() -> Option<bool> {
136 Some(false)
137}
138
139pub mod create_join_link_state {
140
141 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
142 #[allow(unused)]
143 use ::core::marker::PhantomData;
144 mod sealed {
145 pub trait Sealed {}
146 }
147 pub trait State: sealed::Sealed {
149 type ConvoId;
150 type JoinRule;
151 }
152 pub struct Empty(());
154 impl sealed::Sealed for Empty {}
155 impl State for Empty {
156 type ConvoId = Unset;
157 type JoinRule = Unset;
158 }
159 pub struct SetConvoId<St: State = Empty>(PhantomData<fn() -> St>);
161 impl<St: State> sealed::Sealed for SetConvoId<St> {}
162 impl<St: State> State for SetConvoId<St> {
163 type ConvoId = Set<members::convo_id>;
164 type JoinRule = St::JoinRule;
165 }
166 pub struct SetJoinRule<St: State = Empty>(PhantomData<fn() -> St>);
168 impl<St: State> sealed::Sealed for SetJoinRule<St> {}
169 impl<St: State> State for SetJoinRule<St> {
170 type ConvoId = St::ConvoId;
171 type JoinRule = Set<members::join_rule>;
172 }
173 #[allow(non_camel_case_types)]
175 pub mod members {
176 pub struct convo_id(());
178 pub struct join_rule(());
180 }
181}
182
183pub struct CreateJoinLinkBuilder<
185 St: create_join_link_state::State,
186 S: BosStr = DefaultStr,
187> {
188 _state: PhantomData<fn() -> St>,
189 _fields: (Option<S>, Option<JoinRule<S>>, Option<bool>),
190 _type: PhantomData<fn() -> S>,
191}
192
193impl CreateJoinLink<DefaultStr> {
194 pub fn new() -> CreateJoinLinkBuilder<create_join_link_state::Empty, DefaultStr> {
196 CreateJoinLinkBuilder::new()
197 }
198}
199
200impl<S: BosStr> CreateJoinLink<S> {
201 pub fn builder() -> CreateJoinLinkBuilder<create_join_link_state::Empty, S> {
203 CreateJoinLinkBuilder::builder()
204 }
205}
206
207impl CreateJoinLinkBuilder<create_join_link_state::Empty, DefaultStr> {
208 pub fn new() -> Self {
210 CreateJoinLinkBuilder {
211 _state: PhantomData,
212 _fields: (None, None, None),
213 _type: PhantomData,
214 }
215 }
216}
217
218impl<S: BosStr> CreateJoinLinkBuilder<create_join_link_state::Empty, S> {
219 pub fn builder() -> Self {
221 CreateJoinLinkBuilder {
222 _state: PhantomData,
223 _fields: (None, None, None),
224 _type: PhantomData,
225 }
226 }
227}
228
229impl<St, S: BosStr> CreateJoinLinkBuilder<St, S>
230where
231 St: create_join_link_state::State,
232 St::ConvoId: create_join_link_state::IsUnset,
233{
234 pub fn convo_id(
236 mut self,
237 value: impl Into<S>,
238 ) -> CreateJoinLinkBuilder<create_join_link_state::SetConvoId<St>, S> {
239 self._fields.0 = Option::Some(value.into());
240 CreateJoinLinkBuilder {
241 _state: PhantomData,
242 _fields: self._fields,
243 _type: PhantomData,
244 }
245 }
246}
247
248impl<St, S: BosStr> CreateJoinLinkBuilder<St, S>
249where
250 St: create_join_link_state::State,
251 St::JoinRule: create_join_link_state::IsUnset,
252{
253 pub fn join_rule(
255 mut self,
256 value: impl Into<JoinRule<S>>,
257 ) -> CreateJoinLinkBuilder<create_join_link_state::SetJoinRule<St>, S> {
258 self._fields.1 = Option::Some(value.into());
259 CreateJoinLinkBuilder {
260 _state: PhantomData,
261 _fields: self._fields,
262 _type: PhantomData,
263 }
264 }
265}
266
267impl<St: create_join_link_state::State, S: BosStr> CreateJoinLinkBuilder<St, S> {
268 pub fn require_approval(mut self, value: impl Into<Option<bool>>) -> Self {
270 self._fields.2 = value.into();
271 self
272 }
273 pub fn maybe_require_approval(mut self, value: Option<bool>) -> Self {
275 self._fields.2 = value;
276 self
277 }
278}
279
280impl<St, S: BosStr> CreateJoinLinkBuilder<St, S>
281where
282 St: create_join_link_state::State,
283 St::ConvoId: create_join_link_state::IsSet,
284 St::JoinRule: create_join_link_state::IsSet,
285{
286 pub fn build(self) -> CreateJoinLink<S> {
288 CreateJoinLink {
289 convo_id: self._fields.0.unwrap(),
290 join_rule: self._fields.1.unwrap(),
291 require_approval: self._fields.2.or_else(|| Some(false)),
292 extra_data: Default::default(),
293 }
294 }
295 pub fn build_with_data(
297 self,
298 extra_data: BTreeMap<SmolStr, Data<S>>,
299 ) -> CreateJoinLink<S> {
300 CreateJoinLink {
301 convo_id: self._fields.0.unwrap(),
302 join_rule: self._fields.1.unwrap(),
303 require_approval: self._fields.2.or_else(|| Some(false)),
304 extra_data: Some(extra_data),
305 }
306 }
307}