Skip to main content

jacquard_api/chat_bsky/group/
create_group.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: chat.bsky.group.createGroup
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, BosStr, DefaultStr, FromStaticStr};
14use jacquard_common::deps::smol_str::SmolStr;
15use jacquard_common::types::string::Did;
16use jacquard_common::types::value::Data;
17use jacquard_derive::{IntoStatic, open_union};
18use serde::{Serialize, Deserialize};
19use crate::chat_bsky::convo::ConvoView;
20
21#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
22#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
23pub struct CreateGroup<S: BosStr = DefaultStr> {
24    pub members: Vec<Did<S>>,
25    pub name: S,
26    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
27    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
28}
29
30
31#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
32#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
33pub struct CreateGroupOutput<S: BosStr = DefaultStr> {
34    pub convo: ConvoView<S>,
35    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
36    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
37}
38
39
40#[derive(
41    Serialize,
42    Deserialize,
43    Debug,
44    Clone,
45    PartialEq,
46    Eq,
47    thiserror::Error,
48    miette::Diagnostic
49)]
50
51#[serde(tag = "error", content = "message")]
52pub enum CreateGroupError {
53    #[serde(rename = "AccountSuspended")]
54    AccountSuspended(Option<SmolStr>),
55    #[serde(rename = "BlockedActor")]
56    BlockedActor(Option<SmolStr>),
57    #[serde(rename = "BlockedSubject")]
58    BlockedSubject(Option<SmolStr>),
59    #[serde(rename = "NewAccountCannotCreateGroup")]
60    NewAccountCannotCreateGroup(Option<SmolStr>),
61    #[serde(rename = "NotFollowedBySender")]
62    NotFollowedBySender(Option<SmolStr>),
63    #[serde(rename = "RecipientNotFound")]
64    RecipientNotFound(Option<SmolStr>),
65    #[serde(rename = "UserForbidsGroups")]
66    UserForbidsGroups(Option<SmolStr>),
67    /// Catch-all for unknown error codes.
68    #[serde(untagged)]
69    Other { error: SmolStr, message: Option<SmolStr> },
70}
71
72impl core::fmt::Display for CreateGroupError {
73    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
74        match self {
75            Self::AccountSuspended(msg) => {
76                write!(f, "AccountSuspended")?;
77                if let Some(msg) = msg {
78                    write!(f, ": {}", msg)?;
79                }
80                Ok(())
81            }
82            Self::BlockedActor(msg) => {
83                write!(f, "BlockedActor")?;
84                if let Some(msg) = msg {
85                    write!(f, ": {}", msg)?;
86                }
87                Ok(())
88            }
89            Self::BlockedSubject(msg) => {
90                write!(f, "BlockedSubject")?;
91                if let Some(msg) = msg {
92                    write!(f, ": {}", msg)?;
93                }
94                Ok(())
95            }
96            Self::NewAccountCannotCreateGroup(msg) => {
97                write!(f, "NewAccountCannotCreateGroup")?;
98                if let Some(msg) = msg {
99                    write!(f, ": {}", msg)?;
100                }
101                Ok(())
102            }
103            Self::NotFollowedBySender(msg) => {
104                write!(f, "NotFollowedBySender")?;
105                if let Some(msg) = msg {
106                    write!(f, ": {}", msg)?;
107                }
108                Ok(())
109            }
110            Self::RecipientNotFound(msg) => {
111                write!(f, "RecipientNotFound")?;
112                if let Some(msg) = msg {
113                    write!(f, ": {}", msg)?;
114                }
115                Ok(())
116            }
117            Self::UserForbidsGroups(msg) => {
118                write!(f, "UserForbidsGroups")?;
119                if let Some(msg) = msg {
120                    write!(f, ": {}", msg)?;
121                }
122                Ok(())
123            }
124            Self::Other { error, message } => {
125                write!(f, "{}", error)?;
126                if let Some(msg) = message {
127                    write!(f, ": {}", msg)?;
128                }
129                Ok(())
130            }
131        }
132    }
133}
134
135/** Response marker for the `chat.bsky.group.createGroup` procedure.
136
137Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `CreateGroupOutput<S>` for this endpoint.*/
138pub struct CreateGroupResponse;
139impl jacquard_common::xrpc::XrpcResp for CreateGroupResponse {
140    const NSID: &'static str = "chat.bsky.group.createGroup";
141    const ENCODING: &'static str = "application/json";
142    type Output<S: BosStr> = CreateGroupOutput<S>;
143    type Err = CreateGroupError;
144}
145
146impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CreateGroup<S> {
147    const NSID: &'static str = "chat.bsky.group.createGroup";
148    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
149        "application/json",
150    );
151    type Response = CreateGroupResponse;
152}
153
154/** Endpoint marker for the `chat.bsky.group.createGroup` procedure.
155
156Path: `/xrpc/chat.bsky.group.createGroup`. The request payload type is `CreateGroup<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
157pub struct CreateGroupRequest;
158impl jacquard_common::xrpc::XrpcEndpoint for CreateGroupRequest {
159    const PATH: &'static str = "/xrpc/chat.bsky.group.createGroup";
160    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
161        "application/json",
162    );
163    type Request<S: BosStr> = CreateGroup<S>;
164    type Response = CreateGroupResponse;
165}
166
167pub mod create_group_state {
168
169    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
170    #[allow(unused)]
171    use ::core::marker::PhantomData;
172    mod sealed {
173        pub trait Sealed {}
174    }
175    /// State trait tracking which required fields have been set
176    pub trait State: sealed::Sealed {
177        type Members;
178        type Name;
179    }
180    /// Empty state - all required fields are unset
181    pub struct Empty(());
182    impl sealed::Sealed for Empty {}
183    impl State for Empty {
184        type Members = Unset;
185        type Name = Unset;
186    }
187    ///State transition - sets the `members` field to Set
188    pub struct SetMembers<St: State = Empty>(PhantomData<fn() -> St>);
189    impl<St: State> sealed::Sealed for SetMembers<St> {}
190    impl<St: State> State for SetMembers<St> {
191        type Members = Set<members::members>;
192        type Name = St::Name;
193    }
194    ///State transition - sets the `name` field to Set
195    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
196    impl<St: State> sealed::Sealed for SetName<St> {}
197    impl<St: State> State for SetName<St> {
198        type Members = St::Members;
199        type Name = Set<members::name>;
200    }
201    /// Marker types for field names
202    #[allow(non_camel_case_types)]
203    pub mod members {
204        ///Marker type for the `members` field
205        pub struct members(());
206        ///Marker type for the `name` field
207        pub struct name(());
208    }
209}
210
211/// Builder for constructing an instance of this type.
212pub struct CreateGroupBuilder<St: create_group_state::State, S: BosStr = DefaultStr> {
213    _state: PhantomData<fn() -> St>,
214    _fields: (Option<Vec<Did<S>>>, Option<S>),
215    _type: PhantomData<fn() -> S>,
216}
217
218impl CreateGroup<DefaultStr> {
219    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
220    pub fn new() -> CreateGroupBuilder<create_group_state::Empty, DefaultStr> {
221        CreateGroupBuilder::new()
222    }
223}
224
225impl<S: BosStr> CreateGroup<S> {
226    /// Create a new builder for this type
227    pub fn builder() -> CreateGroupBuilder<create_group_state::Empty, S> {
228        CreateGroupBuilder::builder()
229    }
230}
231
232impl CreateGroupBuilder<create_group_state::Empty, DefaultStr> {
233    /// Create a new builder with all fields unset, using the default string type, if needed
234    pub fn new() -> Self {
235        CreateGroupBuilder {
236            _state: PhantomData,
237            _fields: (None, None),
238            _type: PhantomData,
239        }
240    }
241}
242
243impl<S: BosStr> CreateGroupBuilder<create_group_state::Empty, S> {
244    /// Create a new builder with all fields unset
245    pub fn builder() -> Self {
246        CreateGroupBuilder {
247            _state: PhantomData,
248            _fields: (None, None),
249            _type: PhantomData,
250        }
251    }
252}
253
254impl<St, S: BosStr> CreateGroupBuilder<St, S>
255where
256    St: create_group_state::State,
257    St::Members: create_group_state::IsUnset,
258{
259    /// Set the `members` field (required)
260    pub fn members(
261        mut self,
262        value: impl Into<Vec<Did<S>>>,
263    ) -> CreateGroupBuilder<create_group_state::SetMembers<St>, S> {
264        self._fields.0 = Option::Some(value.into());
265        CreateGroupBuilder {
266            _state: PhantomData,
267            _fields: self._fields,
268            _type: PhantomData,
269        }
270    }
271}
272
273impl<St, S: BosStr> CreateGroupBuilder<St, S>
274where
275    St: create_group_state::State,
276    St::Name: create_group_state::IsUnset,
277{
278    /// Set the `name` field (required)
279    pub fn name(
280        mut self,
281        value: impl Into<S>,
282    ) -> CreateGroupBuilder<create_group_state::SetName<St>, S> {
283        self._fields.1 = Option::Some(value.into());
284        CreateGroupBuilder {
285            _state: PhantomData,
286            _fields: self._fields,
287            _type: PhantomData,
288        }
289    }
290}
291
292impl<St, S: BosStr> CreateGroupBuilder<St, S>
293where
294    St: create_group_state::State,
295    St::Members: create_group_state::IsSet,
296    St::Name: create_group_state::IsSet,
297{
298    /// Build the final struct.
299    pub fn build(self) -> CreateGroup<S> {
300        CreateGroup {
301            members: self._fields.0.unwrap(),
302            name: self._fields.1.unwrap(),
303            extra_data: Default::default(),
304        }
305    }
306    /// Build the final struct with custom extra_data.
307    pub fn build_with_data(
308        self,
309        extra_data: BTreeMap<SmolStr, Data<S>>,
310    ) -> CreateGroup<S> {
311        CreateGroup {
312            members: self._fields.0.unwrap(),
313            name: self._fields.1.unwrap(),
314            extra_data: Some(extra_data),
315        }
316    }
317}