jacquard_api/games_gamesgamesgamesgames/
create_contribution.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::deps::smol_str::SmolStr;
14use jacquard_common::types::string::AtUri;
15use jacquard_common::types::value::Data;
16use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
17use jacquard_derive::IntoStatic;
18use serde::{Deserialize, Serialize};
19
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
21#[serde(
22 rename_all = "camelCase",
23 bound(deserialize = "S: Deserialize<'de> + BosStr")
24)]
25pub struct CreateContribution<S: BosStr = DefaultStr> {
26 pub changes: Data<S>,
28 pub contribution_type: CreateContributionContributionType<S>,
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub message: Option<S>,
31 #[serde(skip_serializing_if = "Option::is_none")]
33 pub rkey: Option<S>,
34 #[serde(skip_serializing_if = "Option::is_none")]
36 pub subject: Option<AtUri<S>>,
37 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
38 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
39}
40
41#[derive(Debug, Clone, PartialEq, Eq, Hash)]
42pub enum CreateContributionContributionType<S: BosStr = DefaultStr> {
43 Correction,
44 Addition,
45 NewGame,
46 Other(S),
47}
48
49impl<S: BosStr> CreateContributionContributionType<S> {
50 pub fn as_str(&self) -> &str {
51 match self {
52 Self::Correction => "correction",
53 Self::Addition => "addition",
54 Self::NewGame => "newGame",
55 Self::Other(s) => s.as_ref(),
56 }
57 }
58 pub fn from_value(s: S) -> Self {
60 match s.as_ref() {
61 "correction" => Self::Correction,
62 "addition" => Self::Addition,
63 "newGame" => Self::NewGame,
64 _ => Self::Other(s),
65 }
66 }
67}
68
69impl<S: BosStr> core::fmt::Display for CreateContributionContributionType<S> {
70 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71 write!(f, "{}", self.as_str())
72 }
73}
74
75impl<S: BosStr> AsRef<str> for CreateContributionContributionType<S> {
76 fn as_ref(&self) -> &str {
77 self.as_str()
78 }
79}
80
81impl<S: BosStr> Serialize for CreateContributionContributionType<S> {
82 fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
83 where
84 Ser: serde::Serializer,
85 {
86 serializer.serialize_str(self.as_str())
87 }
88}
89
90impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for CreateContributionContributionType<S> {
91 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
92 where
93 D: serde::Deserializer<'de>,
94 {
95 let s = S::deserialize(deserializer)?;
96 Ok(Self::from_value(s))
97 }
98}
99
100impl<S: BosStr + Default> Default for CreateContributionContributionType<S> {
101 fn default() -> Self {
102 Self::Other(Default::default())
103 }
104}
105
106impl<S: BosStr> jacquard_common::IntoStatic for CreateContributionContributionType<S>
107where
108 S: BosStr + jacquard_common::IntoStatic,
109 S::Output: BosStr,
110{
111 type Output = CreateContributionContributionType<S::Output>;
112 fn into_static(self) -> Self::Output {
113 match self {
114 CreateContributionContributionType::Correction => {
115 CreateContributionContributionType::Correction
116 }
117 CreateContributionContributionType::Addition => {
118 CreateContributionContributionType::Addition
119 }
120 CreateContributionContributionType::NewGame => {
121 CreateContributionContributionType::NewGame
122 }
123 CreateContributionContributionType::Other(v) => {
124 CreateContributionContributionType::Other(v.into_static())
125 }
126 }
127 }
128}
129
130#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
131#[serde(
132 rename_all = "camelCase",
133 bound(deserialize = "S: Deserialize<'de> + BosStr")
134)]
135pub struct CreateContributionOutput<S: BosStr = DefaultStr> {
136 pub uri: AtUri<S>,
137 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
138 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
139}
140
141pub struct CreateContributionResponse;
145impl jacquard_common::xrpc::XrpcResp for CreateContributionResponse {
146 const NSID: &'static str = "games.gamesgamesgamesgames.createContribution";
147 const ENCODING: &'static str = "application/json";
148 type Output<S: BosStr> = CreateContributionOutput<S>;
149 type Err = jacquard_common::xrpc::GenericError;
150}
151
152impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CreateContribution<S> {
153 const NSID: &'static str = "games.gamesgamesgamesgames.createContribution";
154 const METHOD: jacquard_common::xrpc::XrpcMethod =
155 jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
156 type Response = CreateContributionResponse;
157}
158
159pub struct CreateContributionRequest;
163impl jacquard_common::xrpc::XrpcEndpoint for CreateContributionRequest {
164 const PATH: &'static str = "/xrpc/games.gamesgamesgamesgames.createContribution";
165 const METHOD: jacquard_common::xrpc::XrpcMethod =
166 jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
167 type Request<S: BosStr> = CreateContribution<S>;
168 type Response = CreateContributionResponse;
169}
170
171pub mod create_contribution_state {
172
173 pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
174 #[allow(unused)]
175 use ::core::marker::PhantomData;
176 mod sealed {
177 pub trait Sealed {}
178 }
179 pub trait State: sealed::Sealed {
181 type Changes;
182 type ContributionType;
183 }
184 pub struct Empty(());
186 impl sealed::Sealed for Empty {}
187 impl State for Empty {
188 type Changes = Unset;
189 type ContributionType = Unset;
190 }
191 pub struct SetChanges<St: State = Empty>(PhantomData<fn() -> St>);
193 impl<St: State> sealed::Sealed for SetChanges<St> {}
194 impl<St: State> State for SetChanges<St> {
195 type Changes = Set<members::changes>;
196 type ContributionType = St::ContributionType;
197 }
198 pub struct SetContributionType<St: State = Empty>(PhantomData<fn() -> St>);
200 impl<St: State> sealed::Sealed for SetContributionType<St> {}
201 impl<St: State> State for SetContributionType<St> {
202 type Changes = St::Changes;
203 type ContributionType = Set<members::contribution_type>;
204 }
205 #[allow(non_camel_case_types)]
207 pub mod members {
208 pub struct changes(());
210 pub struct contribution_type(());
212 }
213}
214
215pub struct CreateContributionBuilder<St: create_contribution_state::State, S: BosStr = DefaultStr> {
217 _state: PhantomData<fn() -> St>,
218 _fields: (
219 Option<Data<S>>,
220 Option<CreateContributionContributionType<S>>,
221 Option<S>,
222 Option<S>,
223 Option<AtUri<S>>,
224 ),
225 _type: PhantomData<fn() -> S>,
226}
227
228impl CreateContribution<DefaultStr> {
229 pub fn new() -> CreateContributionBuilder<create_contribution_state::Empty, DefaultStr> {
231 CreateContributionBuilder::new()
232 }
233}
234
235impl<S: BosStr> CreateContribution<S> {
236 pub fn builder() -> CreateContributionBuilder<create_contribution_state::Empty, S> {
238 CreateContributionBuilder::builder()
239 }
240}
241
242impl CreateContributionBuilder<create_contribution_state::Empty, DefaultStr> {
243 pub fn new() -> Self {
245 CreateContributionBuilder {
246 _state: PhantomData,
247 _fields: (None, None, None, None, None),
248 _type: PhantomData,
249 }
250 }
251}
252
253impl<S: BosStr> CreateContributionBuilder<create_contribution_state::Empty, S> {
254 pub fn builder() -> Self {
256 CreateContributionBuilder {
257 _state: PhantomData,
258 _fields: (None, None, None, None, None),
259 _type: PhantomData,
260 }
261 }
262}
263
264impl<St, S: BosStr> CreateContributionBuilder<St, S>
265where
266 St: create_contribution_state::State,
267 St::Changes: create_contribution_state::IsUnset,
268{
269 pub fn changes(
271 mut self,
272 value: impl Into<Data<S>>,
273 ) -> CreateContributionBuilder<create_contribution_state::SetChanges<St>, S> {
274 self._fields.0 = Option::Some(value.into());
275 CreateContributionBuilder {
276 _state: PhantomData,
277 _fields: self._fields,
278 _type: PhantomData,
279 }
280 }
281}
282
283impl<St, S: BosStr> CreateContributionBuilder<St, S>
284where
285 St: create_contribution_state::State,
286 St::ContributionType: create_contribution_state::IsUnset,
287{
288 pub fn contribution_type(
290 mut self,
291 value: impl Into<CreateContributionContributionType<S>>,
292 ) -> CreateContributionBuilder<create_contribution_state::SetContributionType<St>, S> {
293 self._fields.1 = Option::Some(value.into());
294 CreateContributionBuilder {
295 _state: PhantomData,
296 _fields: self._fields,
297 _type: PhantomData,
298 }
299 }
300}
301
302impl<St: create_contribution_state::State, S: BosStr> CreateContributionBuilder<St, S> {
303 pub fn message(mut self, value: impl Into<Option<S>>) -> Self {
305 self._fields.2 = value.into();
306 self
307 }
308 pub fn maybe_message(mut self, value: Option<S>) -> Self {
310 self._fields.2 = value;
311 self
312 }
313}
314
315impl<St: create_contribution_state::State, S: BosStr> CreateContributionBuilder<St, S> {
316 pub fn rkey(mut self, value: impl Into<Option<S>>) -> Self {
318 self._fields.3 = value.into();
319 self
320 }
321 pub fn maybe_rkey(mut self, value: Option<S>) -> Self {
323 self._fields.3 = value;
324 self
325 }
326}
327
328impl<St: create_contribution_state::State, S: BosStr> CreateContributionBuilder<St, S> {
329 pub fn subject(mut self, value: impl Into<Option<AtUri<S>>>) -> Self {
331 self._fields.4 = value.into();
332 self
333 }
334 pub fn maybe_subject(mut self, value: Option<AtUri<S>>) -> Self {
336 self._fields.4 = value;
337 self
338 }
339}
340
341impl<St, S: BosStr> CreateContributionBuilder<St, S>
342where
343 St: create_contribution_state::State,
344 St::Changes: create_contribution_state::IsSet,
345 St::ContributionType: create_contribution_state::IsSet,
346{
347 pub fn build(self) -> CreateContribution<S> {
349 CreateContribution {
350 changes: self._fields.0.unwrap(),
351 contribution_type: self._fields.1.unwrap(),
352 message: self._fields.2,
353 rkey: self._fields.3,
354 subject: self._fields.4,
355 extra_data: Default::default(),
356 }
357 }
358 pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> CreateContribution<S> {
360 CreateContribution {
361 changes: self._fields.0.unwrap(),
362 contribution_type: self._fields.1.unwrap(),
363 message: self._fields.2,
364 rkey: self._fields.3,
365 subject: self._fields.4,
366 extra_data: Some(extra_data),
367 }
368 }
369}