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