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