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