Skip to main content

jacquard_api/sh_weaver/collab/
accept.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: sh.weaver.collab.accept
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;
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::types::collection::{Collection, RecordError};
18use jacquard_common::types::string::{AtUri, Cid, Datetime};
19use jacquard_common::types::uri::{RecordUri, UriError};
20use jacquard_common::xrpc::XrpcResp;
21use jacquard_derive::{IntoStatic, lexicon};
22use jacquard_lexicon::lexicon::LexiconDoc;
23use jacquard_lexicon::schema::LexiconSchema;
24
25#[allow(unused_imports)]
26use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
27use serde::{Serialize, Deserialize};
28use crate::com_atproto::repo::strong_ref::StrongRef;
29/// Acceptance of a collaboration invite. Completes the two-way agreement.
30
31#[lexicon]
32#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
33#[serde(rename_all = "camelCase", rename = "sh.weaver.collab.accept", tag = "$type")]
34pub struct Accept<'a> {
35    pub created_at: Datetime,
36    ///Reference to the invite record being accepted.
37    #[serde(borrow)]
38    pub invite: StrongRef<'a>,
39    ///URI of the resource (denormalized for easier querying).
40    #[serde(borrow)]
41    pub resource: AtUri<'a>,
42}
43
44/// Typed wrapper for GetRecord response with this collection's record type.
45
46#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
47#[serde(rename_all = "camelCase")]
48pub struct AcceptGetRecordOutput<'a> {
49    #[serde(skip_serializing_if = "Option::is_none")]
50    #[serde(borrow)]
51    pub cid: Option<Cid<'a>>,
52    #[serde(borrow)]
53    pub uri: AtUri<'a>,
54    #[serde(borrow)]
55    pub value: Accept<'a>,
56}
57
58impl<'a> Accept<'a> {
59    pub fn uri(
60        uri: impl Into<CowStr<'a>>,
61    ) -> Result<RecordUri<'a, AcceptRecord>, UriError> {
62        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
63    }
64}
65
66/// Marker type for deserializing records from this collection.
67
68#[derive(Debug, Serialize, Deserialize)]
69pub struct AcceptRecord;
70impl XrpcResp for AcceptRecord {
71    const NSID: &'static str = "sh.weaver.collab.accept";
72    const ENCODING: &'static str = "application/json";
73    type Output<'de> = AcceptGetRecordOutput<'de>;
74    type Err<'de> = RecordError<'de>;
75}
76
77impl From<AcceptGetRecordOutput<'_>> for Accept<'_> {
78    fn from(output: AcceptGetRecordOutput<'_>) -> Self {
79        use jacquard_common::IntoStatic;
80        output.value.into_static()
81    }
82}
83
84impl Collection for Accept<'_> {
85    const NSID: &'static str = "sh.weaver.collab.accept";
86    type Record = AcceptRecord;
87}
88
89impl Collection for AcceptRecord {
90    const NSID: &'static str = "sh.weaver.collab.accept";
91    type Record = AcceptRecord;
92}
93
94impl<'a> LexiconSchema for Accept<'a> {
95    fn nsid() -> &'static str {
96        "sh.weaver.collab.accept"
97    }
98    fn def_name() -> &'static str {
99        "main"
100    }
101    fn lexicon_doc() -> LexiconDoc<'static> {
102        lexicon_doc_sh_weaver_collab_accept()
103    }
104    fn validate(&self) -> Result<(), ConstraintError> {
105        Ok(())
106    }
107}
108
109pub mod accept_state {
110
111    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
112    #[allow(unused)]
113    use ::core::marker::PhantomData;
114    mod sealed {
115        pub trait Sealed {}
116    }
117    /// State trait tracking which required fields have been set
118    pub trait State: sealed::Sealed {
119        type Invite;
120        type Resource;
121        type CreatedAt;
122    }
123    /// Empty state - all required fields are unset
124    pub struct Empty(());
125    impl sealed::Sealed for Empty {}
126    impl State for Empty {
127        type Invite = Unset;
128        type Resource = Unset;
129        type CreatedAt = Unset;
130    }
131    ///State transition - sets the `invite` field to Set
132    pub struct SetInvite<S: State = Empty>(PhantomData<fn() -> S>);
133    impl<S: State> sealed::Sealed for SetInvite<S> {}
134    impl<S: State> State for SetInvite<S> {
135        type Invite = Set<members::invite>;
136        type Resource = S::Resource;
137        type CreatedAt = S::CreatedAt;
138    }
139    ///State transition - sets the `resource` field to Set
140    pub struct SetResource<S: State = Empty>(PhantomData<fn() -> S>);
141    impl<S: State> sealed::Sealed for SetResource<S> {}
142    impl<S: State> State for SetResource<S> {
143        type Invite = S::Invite;
144        type Resource = Set<members::resource>;
145        type CreatedAt = S::CreatedAt;
146    }
147    ///State transition - sets the `created_at` field to Set
148    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
149    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
150    impl<S: State> State for SetCreatedAt<S> {
151        type Invite = S::Invite;
152        type Resource = S::Resource;
153        type CreatedAt = Set<members::created_at>;
154    }
155    /// Marker types for field names
156    #[allow(non_camel_case_types)]
157    pub mod members {
158        ///Marker type for the `invite` field
159        pub struct invite(());
160        ///Marker type for the `resource` field
161        pub struct resource(());
162        ///Marker type for the `created_at` field
163        pub struct created_at(());
164    }
165}
166
167/// Builder for constructing an instance of this type
168pub struct AcceptBuilder<'a, S: accept_state::State> {
169    _state: PhantomData<fn() -> S>,
170    _fields: (Option<Datetime>, Option<StrongRef<'a>>, Option<AtUri<'a>>),
171    _lifetime: PhantomData<&'a ()>,
172}
173
174impl<'a> Accept<'a> {
175    /// Create a new builder for this type
176    pub fn new() -> AcceptBuilder<'a, accept_state::Empty> {
177        AcceptBuilder::new()
178    }
179}
180
181impl<'a> AcceptBuilder<'a, accept_state::Empty> {
182    /// Create a new builder with all fields unset
183    pub fn new() -> Self {
184        AcceptBuilder {
185            _state: PhantomData,
186            _fields: (None, None, None),
187            _lifetime: PhantomData,
188        }
189    }
190}
191
192impl<'a, S> AcceptBuilder<'a, S>
193where
194    S: accept_state::State,
195    S::CreatedAt: accept_state::IsUnset,
196{
197    /// Set the `createdAt` field (required)
198    pub fn created_at(
199        mut self,
200        value: impl Into<Datetime>,
201    ) -> AcceptBuilder<'a, accept_state::SetCreatedAt<S>> {
202        self._fields.0 = Option::Some(value.into());
203        AcceptBuilder {
204            _state: PhantomData,
205            _fields: self._fields,
206            _lifetime: PhantomData,
207        }
208    }
209}
210
211impl<'a, S> AcceptBuilder<'a, S>
212where
213    S: accept_state::State,
214    S::Invite: accept_state::IsUnset,
215{
216    /// Set the `invite` field (required)
217    pub fn invite(
218        mut self,
219        value: impl Into<StrongRef<'a>>,
220    ) -> AcceptBuilder<'a, accept_state::SetInvite<S>> {
221        self._fields.1 = Option::Some(value.into());
222        AcceptBuilder {
223            _state: PhantomData,
224            _fields: self._fields,
225            _lifetime: PhantomData,
226        }
227    }
228}
229
230impl<'a, S> AcceptBuilder<'a, S>
231where
232    S: accept_state::State,
233    S::Resource: accept_state::IsUnset,
234{
235    /// Set the `resource` field (required)
236    pub fn resource(
237        mut self,
238        value: impl Into<AtUri<'a>>,
239    ) -> AcceptBuilder<'a, accept_state::SetResource<S>> {
240        self._fields.2 = Option::Some(value.into());
241        AcceptBuilder {
242            _state: PhantomData,
243            _fields: self._fields,
244            _lifetime: PhantomData,
245        }
246    }
247}
248
249impl<'a, S> AcceptBuilder<'a, S>
250where
251    S: accept_state::State,
252    S::Invite: accept_state::IsSet,
253    S::Resource: accept_state::IsSet,
254    S::CreatedAt: accept_state::IsSet,
255{
256    /// Build the final struct
257    pub fn build(self) -> Accept<'a> {
258        Accept {
259            created_at: self._fields.0.unwrap(),
260            invite: self._fields.1.unwrap(),
261            resource: self._fields.2.unwrap(),
262            extra_data: Default::default(),
263        }
264    }
265    /// Build the final struct with custom extra_data
266    pub fn build_with_data(
267        self,
268        extra_data: BTreeMap<
269            jacquard_common::deps::smol_str::SmolStr,
270            jacquard_common::types::value::Data<'a>,
271        >,
272    ) -> Accept<'a> {
273        Accept {
274            created_at: self._fields.0.unwrap(),
275            invite: self._fields.1.unwrap(),
276            resource: self._fields.2.unwrap(),
277            extra_data: Some(extra_data),
278        }
279    }
280}
281
282fn lexicon_doc_sh_weaver_collab_accept() -> LexiconDoc<'static> {
283    #[allow(unused_imports)]
284    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
285    use jacquard_lexicon::lexicon::*;
286    use alloc::collections::BTreeMap;
287    LexiconDoc {
288        lexicon: Lexicon::Lexicon1,
289        id: CowStr::new_static("sh.weaver.collab.accept"),
290        defs: {
291            let mut map = BTreeMap::new();
292            map.insert(
293                SmolStr::new_static("main"),
294                LexUserType::Record(LexRecord {
295                    description: Some(
296                        CowStr::new_static(
297                            "Acceptance of a collaboration invite. Completes the two-way agreement.",
298                        ),
299                    ),
300                    key: Some(CowStr::new_static("tid")),
301                    record: LexRecordRecord::Object(LexObject {
302                        required: Some(
303                            vec![
304                                SmolStr::new_static("invite"),
305                                SmolStr::new_static("resource"),
306                                SmolStr::new_static("createdAt")
307                            ],
308                        ),
309                        properties: {
310                            #[allow(unused_mut)]
311                            let mut map = BTreeMap::new();
312                            map.insert(
313                                SmolStr::new_static("createdAt"),
314                                LexObjectProperty::String(LexString {
315                                    format: Some(LexStringFormat::Datetime),
316                                    ..Default::default()
317                                }),
318                            );
319                            map.insert(
320                                SmolStr::new_static("invite"),
321                                LexObjectProperty::Ref(LexRef {
322                                    r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
323                                    ..Default::default()
324                                }),
325                            );
326                            map.insert(
327                                SmolStr::new_static("resource"),
328                                LexObjectProperty::String(LexString {
329                                    description: Some(
330                                        CowStr::new_static(
331                                            "URI of the resource (denormalized for easier querying).",
332                                        ),
333                                    ),
334                                    format: Some(LexStringFormat::AtUri),
335                                    ..Default::default()
336                                }),
337                            );
338                            map
339                        },
340                        ..Default::default()
341                    }),
342                    ..Default::default()
343                }),
344            );
345            map
346        },
347        ..Default::default()
348    }
349}