Skip to main content

jacquard_api/games_gamesgamesgamesgames/
contribution_patch.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: games.gamesgamesgamesgames.contributionPatch
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::{BosStr, CowStr, DefaultStr, FromStaticStr};
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::deps::smol_str::SmolStr;
18use jacquard_common::types::collection::{Collection, RecordError};
19use jacquard_common::types::string::{AtUri, Cid, Datetime};
20use jacquard_common::types::uri::{RecordUri, UriError};
21use jacquard_common::types::value::Data;
22use jacquard_common::xrpc::XrpcResp;
23use jacquard_derive::{IntoStatic, lexicon};
24use jacquard_lexicon::lexicon::LexiconDoc;
25use jacquard_lexicon::schema::LexiconSchema;
26
27use crate::com_atproto::repo::strong_ref::StrongRef;
28#[allow(unused_imports)]
29use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
30use serde::{Deserialize, Serialize};
31/// A mod-approved patch representing changes to apply to an entity. Created on mod approval, deleted when the entity owner accepts and merges.
32
33#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
34#[serde(
35    rename_all = "camelCase",
36    rename = "games.gamesgamesgamesgames.contributionPatch",
37    tag = "$type",
38    bound(deserialize = "S: Deserialize<'de> + BosStr")
39)]
40pub struct ContributionPatch<S: BosStr = DefaultStr> {
41    ///The approved changes to overlay on the entity.
42    pub changes: Data<S>,
43    pub contribution: StrongRef<S>,
44    pub contribution_review: StrongRef<S>,
45    pub created_at: Datetime,
46    ///The entity these changes apply to. Absent for newGame contributions.
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub subject: Option<AtUri<S>>,
49    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
50    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
51}
52
53/// Typed wrapper for GetRecord response with this collection's record type.
54
55#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
56#[serde(rename_all = "camelCase")]
57pub struct ContributionPatchGetRecordOutput<S: BosStr = DefaultStr> {
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub cid: Option<Cid<S>>,
60    pub uri: AtUri<S>,
61    pub value: ContributionPatch<S>,
62}
63
64impl<S: BosStr> ContributionPatch<S> {
65    pub fn uri(uri: S) -> Result<RecordUri<S, ContributionPatchRecord>, UriError> {
66        RecordUri::try_from_uri(AtUri::new(uri)?)
67    }
68}
69
70/// Marker type for deserializing records from this collection.
71
72#[derive(Debug, Serialize, Deserialize)]
73pub struct ContributionPatchRecord;
74impl XrpcResp for ContributionPatchRecord {
75    const NSID: &'static str = "games.gamesgamesgamesgames.contributionPatch";
76    const ENCODING: &'static str = "application/json";
77    type Output<S: BosStr> = ContributionPatchGetRecordOutput<S>;
78    type Err = RecordError;
79}
80
81impl<S: BosStr> From<ContributionPatchGetRecordOutput<S>> for ContributionPatch<S> {
82    fn from(output: ContributionPatchGetRecordOutput<S>) -> Self {
83        output.value
84    }
85}
86
87impl<S: BosStr> Collection for ContributionPatch<S> {
88    const NSID: &'static str = "games.gamesgamesgamesgames.contributionPatch";
89    type Record = ContributionPatchRecord;
90}
91
92impl Collection for ContributionPatchRecord {
93    const NSID: &'static str = "games.gamesgamesgamesgames.contributionPatch";
94    type Record = ContributionPatchRecord;
95}
96
97impl<S: BosStr> LexiconSchema for ContributionPatch<S> {
98    fn nsid() -> &'static str {
99        "games.gamesgamesgamesgames.contributionPatch"
100    }
101    fn def_name() -> &'static str {
102        "main"
103    }
104    fn lexicon_doc() -> LexiconDoc<'static> {
105        lexicon_doc_games_gamesgamesgamesgames_contributionPatch()
106    }
107    fn validate(&self) -> Result<(), ConstraintError> {
108        Ok(())
109    }
110}
111
112pub mod contribution_patch_state {
113
114    pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
115    #[allow(unused)]
116    use ::core::marker::PhantomData;
117    mod sealed {
118        pub trait Sealed {}
119    }
120    /// State trait tracking which required fields have been set
121    pub trait State: sealed::Sealed {
122        type Changes;
123        type Contribution;
124        type ContributionReview;
125        type CreatedAt;
126    }
127    /// Empty state - all required fields are unset
128    pub struct Empty(());
129    impl sealed::Sealed for Empty {}
130    impl State for Empty {
131        type Changes = Unset;
132        type Contribution = Unset;
133        type ContributionReview = Unset;
134        type CreatedAt = Unset;
135    }
136    ///State transition - sets the `changes` field to Set
137    pub struct SetChanges<St: State = Empty>(PhantomData<fn() -> St>);
138    impl<St: State> sealed::Sealed for SetChanges<St> {}
139    impl<St: State> State for SetChanges<St> {
140        type Changes = Set<members::changes>;
141        type Contribution = St::Contribution;
142        type ContributionReview = St::ContributionReview;
143        type CreatedAt = St::CreatedAt;
144    }
145    ///State transition - sets the `contribution` field to Set
146    pub struct SetContribution<St: State = Empty>(PhantomData<fn() -> St>);
147    impl<St: State> sealed::Sealed for SetContribution<St> {}
148    impl<St: State> State for SetContribution<St> {
149        type Changes = St::Changes;
150        type Contribution = Set<members::contribution>;
151        type ContributionReview = St::ContributionReview;
152        type CreatedAt = St::CreatedAt;
153    }
154    ///State transition - sets the `contribution_review` field to Set
155    pub struct SetContributionReview<St: State = Empty>(PhantomData<fn() -> St>);
156    impl<St: State> sealed::Sealed for SetContributionReview<St> {}
157    impl<St: State> State for SetContributionReview<St> {
158        type Changes = St::Changes;
159        type Contribution = St::Contribution;
160        type ContributionReview = Set<members::contribution_review>;
161        type CreatedAt = St::CreatedAt;
162    }
163    ///State transition - sets the `created_at` field to Set
164    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
165    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
166    impl<St: State> State for SetCreatedAt<St> {
167        type Changes = St::Changes;
168        type Contribution = St::Contribution;
169        type ContributionReview = St::ContributionReview;
170        type CreatedAt = Set<members::created_at>;
171    }
172    /// Marker types for field names
173    #[allow(non_camel_case_types)]
174    pub mod members {
175        ///Marker type for the `changes` field
176        pub struct changes(());
177        ///Marker type for the `contribution` field
178        pub struct contribution(());
179        ///Marker type for the `contribution_review` field
180        pub struct contribution_review(());
181        ///Marker type for the `created_at` field
182        pub struct created_at(());
183    }
184}
185
186/// Builder for constructing an instance of this type.
187pub struct ContributionPatchBuilder<St: contribution_patch_state::State, S: BosStr = DefaultStr> {
188    _state: PhantomData<fn() -> St>,
189    _fields: (
190        Option<Data<S>>,
191        Option<StrongRef<S>>,
192        Option<StrongRef<S>>,
193        Option<Datetime>,
194        Option<AtUri<S>>,
195    ),
196    _type: PhantomData<fn() -> S>,
197}
198
199impl ContributionPatch<DefaultStr> {
200    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
201    pub fn new() -> ContributionPatchBuilder<contribution_patch_state::Empty, DefaultStr> {
202        ContributionPatchBuilder::new()
203    }
204}
205
206impl<S: BosStr> ContributionPatch<S> {
207    /// Create a new builder for this type
208    pub fn builder() -> ContributionPatchBuilder<contribution_patch_state::Empty, S> {
209        ContributionPatchBuilder::builder()
210    }
211}
212
213impl ContributionPatchBuilder<contribution_patch_state::Empty, DefaultStr> {
214    /// Create a new builder with all fields unset, using the default string type, if needed
215    pub fn new() -> Self {
216        ContributionPatchBuilder {
217            _state: PhantomData,
218            _fields: (None, None, None, None, None),
219            _type: PhantomData,
220        }
221    }
222}
223
224impl<S: BosStr> ContributionPatchBuilder<contribution_patch_state::Empty, S> {
225    /// Create a new builder with all fields unset
226    pub fn builder() -> Self {
227        ContributionPatchBuilder {
228            _state: PhantomData,
229            _fields: (None, None, None, None, None),
230            _type: PhantomData,
231        }
232    }
233}
234
235impl<St, S: BosStr> ContributionPatchBuilder<St, S>
236where
237    St: contribution_patch_state::State,
238    St::Changes: contribution_patch_state::IsUnset,
239{
240    /// Set the `changes` field (required)
241    pub fn changes(
242        mut self,
243        value: impl Into<Data<S>>,
244    ) -> ContributionPatchBuilder<contribution_patch_state::SetChanges<St>, S> {
245        self._fields.0 = Option::Some(value.into());
246        ContributionPatchBuilder {
247            _state: PhantomData,
248            _fields: self._fields,
249            _type: PhantomData,
250        }
251    }
252}
253
254impl<St, S: BosStr> ContributionPatchBuilder<St, S>
255where
256    St: contribution_patch_state::State,
257    St::Contribution: contribution_patch_state::IsUnset,
258{
259    /// Set the `contribution` field (required)
260    pub fn contribution(
261        mut self,
262        value: impl Into<StrongRef<S>>,
263    ) -> ContributionPatchBuilder<contribution_patch_state::SetContribution<St>, S> {
264        self._fields.1 = Option::Some(value.into());
265        ContributionPatchBuilder {
266            _state: PhantomData,
267            _fields: self._fields,
268            _type: PhantomData,
269        }
270    }
271}
272
273impl<St, S: BosStr> ContributionPatchBuilder<St, S>
274where
275    St: contribution_patch_state::State,
276    St::ContributionReview: contribution_patch_state::IsUnset,
277{
278    /// Set the `contributionReview` field (required)
279    pub fn contribution_review(
280        mut self,
281        value: impl Into<StrongRef<S>>,
282    ) -> ContributionPatchBuilder<contribution_patch_state::SetContributionReview<St>, S> {
283        self._fields.2 = Option::Some(value.into());
284        ContributionPatchBuilder {
285            _state: PhantomData,
286            _fields: self._fields,
287            _type: PhantomData,
288        }
289    }
290}
291
292impl<St, S: BosStr> ContributionPatchBuilder<St, S>
293where
294    St: contribution_patch_state::State,
295    St::CreatedAt: contribution_patch_state::IsUnset,
296{
297    /// Set the `createdAt` field (required)
298    pub fn created_at(
299        mut self,
300        value: impl Into<Datetime>,
301    ) -> ContributionPatchBuilder<contribution_patch_state::SetCreatedAt<St>, S> {
302        self._fields.3 = Option::Some(value.into());
303        ContributionPatchBuilder {
304            _state: PhantomData,
305            _fields: self._fields,
306            _type: PhantomData,
307        }
308    }
309}
310
311impl<St: contribution_patch_state::State, S: BosStr> ContributionPatchBuilder<St, S> {
312    /// Set the `subject` field (optional)
313    pub fn subject(mut self, value: impl Into<Option<AtUri<S>>>) -> Self {
314        self._fields.4 = value.into();
315        self
316    }
317    /// Set the `subject` field to an Option value (optional)
318    pub fn maybe_subject(mut self, value: Option<AtUri<S>>) -> Self {
319        self._fields.4 = value;
320        self
321    }
322}
323
324impl<St, S: BosStr> ContributionPatchBuilder<St, S>
325where
326    St: contribution_patch_state::State,
327    St::Changes: contribution_patch_state::IsSet,
328    St::Contribution: contribution_patch_state::IsSet,
329    St::ContributionReview: contribution_patch_state::IsSet,
330    St::CreatedAt: contribution_patch_state::IsSet,
331{
332    /// Build the final struct.
333    pub fn build(self) -> ContributionPatch<S> {
334        ContributionPatch {
335            changes: self._fields.0.unwrap(),
336            contribution: self._fields.1.unwrap(),
337            contribution_review: self._fields.2.unwrap(),
338            created_at: self._fields.3.unwrap(),
339            subject: self._fields.4,
340            extra_data: Default::default(),
341        }
342    }
343    /// Build the final struct with custom extra_data.
344    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> ContributionPatch<S> {
345        ContributionPatch {
346            changes: self._fields.0.unwrap(),
347            contribution: self._fields.1.unwrap(),
348            contribution_review: self._fields.2.unwrap(),
349            created_at: self._fields.3.unwrap(),
350            subject: self._fields.4,
351            extra_data: Some(extra_data),
352        }
353    }
354}
355
356fn lexicon_doc_games_gamesgamesgamesgames_contributionPatch() -> LexiconDoc<'static> {
357    use alloc::collections::BTreeMap;
358    #[allow(unused_imports)]
359    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
360    use jacquard_lexicon::lexicon::*;
361    LexiconDoc {
362        lexicon: Lexicon::Lexicon1,
363        id: CowStr::new_static("games.gamesgamesgamesgames.contributionPatch"),
364        defs: {
365            let mut map = BTreeMap::new();
366            map.insert(
367                SmolStr::new_static("main"),
368                LexUserType::Record(LexRecord {
369                    description: Some(
370                        CowStr::new_static(
371                            "A mod-approved patch representing changes to apply to an entity. Created on mod approval, deleted when the entity owner accepts and merges.",
372                        ),
373                    ),
374                    key: Some(CowStr::new_static("tid")),
375                    record: LexRecordRecord::Object(LexObject {
376                        required: Some(
377                            vec![
378                                SmolStr::new_static("contribution"),
379                                SmolStr::new_static("contributionReview"),
380                                SmolStr::new_static("changes"),
381                                SmolStr::new_static("createdAt")
382                            ],
383                        ),
384                        properties: {
385                            #[allow(unused_mut)]
386                            let mut map = BTreeMap::new();
387                            map.insert(
388                                SmolStr::new_static("changes"),
389                                LexObjectProperty::Unknown(LexUnknown {
390                                    ..Default::default()
391                                }),
392                            );
393                            map.insert(
394                                SmolStr::new_static("contribution"),
395                                LexObjectProperty::Ref(LexRef {
396                                    r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
397                                    ..Default::default()
398                                }),
399                            );
400                            map.insert(
401                                SmolStr::new_static("contributionReview"),
402                                LexObjectProperty::Ref(LexRef {
403                                    r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
404                                    ..Default::default()
405                                }),
406                            );
407                            map.insert(
408                                SmolStr::new_static("createdAt"),
409                                LexObjectProperty::String(LexString {
410                                    format: Some(LexStringFormat::Datetime),
411                                    ..Default::default()
412                                }),
413                            );
414                            map.insert(
415                                SmolStr::new_static("subject"),
416                                LexObjectProperty::String(LexString {
417                                    description: Some(
418                                        CowStr::new_static(
419                                            "The entity these changes apply to. Absent for newGame contributions.",
420                                        ),
421                                    ),
422                                    format: Some(LexStringFormat::AtUri),
423                                    ..Default::default()
424                                }),
425                            );
426                            map
427                        },
428                        ..Default::default()
429                    }),
430                    ..Default::default()
431                }),
432            );
433            map
434        },
435        ..Default::default()
436    }
437}