1use super::{configuration, Error};
2use crate::{apis::ResponseContent, models};
3use reqwest::StatusCode;
4use serde::{Deserialize, Serialize};
5
6#[derive(Clone, Debug)]
8pub struct CreateAccountParams {
9 pub add_account_schema: models::AddAccountSchema,
10}
11
12impl CreateAccountParams {
13 pub fn new(add_account_schema: models::AddAccountSchema) -> Self {
14 Self { add_account_schema }
15 }
16}
17
18#[derive(Clone, Debug)]
20pub struct ForgotPasswordParams {
21 pub password_reset_request_schema: models::PasswordResetRequestSchema,
22}
23
24impl ForgotPasswordParams {
25 pub fn new(password_reset_request_schema: models::PasswordResetRequestSchema) -> Self {
26 Self {
27 password_reset_request_schema,
28 }
29 }
30}
31
32#[derive(Clone, Debug)]
34pub struct GetAccountParams {
35 pub account: String,
37}
38
39impl GetAccountParams {
40 pub fn new(account: String) -> Self {
41 Self { account }
42 }
43}
44
45#[derive(Clone, Debug)]
47pub struct GetAccountAchievementsParams {
48 pub account: String,
50 pub r#type: Option<String>,
52 pub completed: Option<bool>,
54 pub page: Option<u32>,
56 pub size: Option<u32>,
58}
59
60impl GetAccountAchievementsParams {
61 pub fn new(
62 account: String,
63 r#type: Option<String>,
64 completed: Option<bool>,
65 page: Option<u32>,
66 size: Option<u32>,
67 ) -> Self {
68 Self {
69 account,
70 r#type,
71 completed,
72 page,
73 size,
74 }
75 }
76}
77
78#[derive(Clone, Debug)]
80pub struct GetAccountCharactersParams {
81 pub account: String,
83}
84
85impl GetAccountCharactersParams {
86 pub fn new(account: String) -> Self {
87 Self { account }
88 }
89}
90
91#[derive(Clone, Debug)]
93pub struct ResetPasswordParams {
94 pub password_reset_confirm_schema: models::PasswordResetConfirmSchema,
95}
96
97impl ResetPasswordParams {
98 pub fn new(password_reset_confirm_schema: models::PasswordResetConfirmSchema) -> Self {
99 Self {
100 password_reset_confirm_schema,
101 }
102 }
103}
104
105#[derive(Debug, Clone, Serialize, Deserialize)]
107#[serde(untagged)]
108pub enum CreateAccountError {
109 Status456,
111 Status457,
113}
114
115impl TryFrom<StatusCode> for CreateAccountError {
116 type Error = &'static str;
117 #[allow(clippy::match_single_binding)]
118 fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
119 match status.as_u16() {
120 456 => Ok(Self::Status456),
121 457 => Ok(Self::Status457),
122 _ => Err("status code not in spec"),
123 }
124 }
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize)]
129#[serde(untagged)]
130pub enum ForgotPasswordError {}
131
132impl TryFrom<StatusCode> for ForgotPasswordError {
133 type Error = &'static str;
134 #[allow(clippy::match_single_binding)]
135 fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
136 match status.as_u16() {
137 _ => Err("status code not in spec"),
138 }
139 }
140}
141
142#[derive(Debug, Clone, Serialize, Deserialize)]
144#[serde(untagged)]
145pub enum GetAccountError {
146 Status404,
148}
149
150impl TryFrom<StatusCode> for GetAccountError {
151 type Error = &'static str;
152 #[allow(clippy::match_single_binding)]
153 fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
154 match status.as_u16() {
155 404 => Ok(Self::Status404),
156 _ => Err("status code not in spec"),
157 }
158 }
159}
160
161#[derive(Debug, Clone, Serialize, Deserialize)]
163#[serde(untagged)]
164pub enum GetAccountAchievementsError {
165 Status404,
167}
168
169impl TryFrom<StatusCode> for GetAccountAchievementsError {
170 type Error = &'static str;
171 #[allow(clippy::match_single_binding)]
172 fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
173 match status.as_u16() {
174 404 => Ok(Self::Status404),
175 _ => Err("status code not in spec"),
176 }
177 }
178}
179
180#[derive(Debug, Clone, Serialize, Deserialize)]
182#[serde(untagged)]
183pub enum GetAccountCharactersError {}
184
185impl TryFrom<StatusCode> for GetAccountCharactersError {
186 type Error = &'static str;
187 #[allow(clippy::match_single_binding)]
188 fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
189 match status.as_u16() {
190 _ => Err("status code not in spec"),
191 }
192 }
193}
194
195#[derive(Debug, Clone, Serialize, Deserialize)]
197#[serde(untagged)]
198pub enum ResetPasswordError {
199 Status561,
201 Status562,
203 Status560,
205}
206
207impl TryFrom<StatusCode> for ResetPasswordError {
208 type Error = &'static str;
209 #[allow(clippy::match_single_binding)]
210 fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
211 match status.as_u16() {
212 561 => Ok(Self::Status561),
213 562 => Ok(Self::Status562),
214 560 => Ok(Self::Status560),
215 _ => Err("status code not in spec"),
216 }
217 }
218}
219
220pub async fn create_account(
221 configuration: &configuration::Configuration,
222 params: CreateAccountParams,
223) -> Result<models::ResponseSchema, Error<CreateAccountError>> {
224 let local_var_configuration = configuration;
225
226 let add_account_schema = params.add_account_schema;
228
229 let local_var_client = &local_var_configuration.client;
230
231 let local_var_uri_str = format!("{}/accounts/create", local_var_configuration.base_path);
232 let mut local_var_req_builder =
233 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
234
235 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
236 local_var_req_builder =
237 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
238 }
239 local_var_req_builder = local_var_req_builder.json(&add_account_schema);
240
241 let local_var_req = local_var_req_builder.build()?;
242 let local_var_resp = local_var_client.execute(local_var_req).await?;
243
244 let local_var_status = local_var_resp.status();
245 let local_var_content = local_var_resp.text().await?;
246
247 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
248 serde_json::from_str(&local_var_content).map_err(Error::from)
249 } else {
250 let local_var_entity: Option<CreateAccountError> = local_var_status.try_into().ok();
251 let local_var_error = ResponseContent {
252 status: local_var_status,
253 content: local_var_content,
254 entity: local_var_entity,
255 };
256 Err(Error::ResponseError(local_var_error))
257 }
258}
259
260pub async fn forgot_password(
262 configuration: &configuration::Configuration,
263 params: ForgotPasswordParams,
264) -> Result<models::PasswordResetResponseSchema, Error<ForgotPasswordError>> {
265 let local_var_configuration = configuration;
266
267 let password_reset_request_schema = params.password_reset_request_schema;
269
270 let local_var_client = &local_var_configuration.client;
271
272 let local_var_uri_str = format!(
273 "{}/accounts/forgot_password",
274 local_var_configuration.base_path
275 );
276 let mut local_var_req_builder =
277 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
278
279 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
280 local_var_req_builder =
281 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
282 }
283 local_var_req_builder = local_var_req_builder.json(&password_reset_request_schema);
284
285 let local_var_req = local_var_req_builder.build()?;
286 let local_var_resp = local_var_client.execute(local_var_req).await?;
287
288 let local_var_status = local_var_resp.status();
289 let local_var_content = local_var_resp.text().await?;
290
291 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
292 serde_json::from_str(&local_var_content).map_err(Error::from)
293 } else {
294 let local_var_entity: Option<ForgotPasswordError> = local_var_status.try_into().ok();
295 let local_var_error = ResponseContent {
296 status: local_var_status,
297 content: local_var_content,
298 entity: local_var_entity,
299 };
300 Err(Error::ResponseError(local_var_error))
301 }
302}
303
304pub async fn get_account(
306 configuration: &configuration::Configuration,
307 params: GetAccountParams,
308) -> Result<models::AccountDetailsSchema, Error<GetAccountError>> {
309 let local_var_configuration = configuration;
310
311 let account = params.account;
313
314 let local_var_client = &local_var_configuration.client;
315
316 let local_var_uri_str = format!(
317 "{}/accounts/{account}",
318 local_var_configuration.base_path,
319 account = crate::apis::urlencode(account)
320 );
321 let mut local_var_req_builder =
322 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
323
324 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
325 local_var_req_builder =
326 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
327 }
328
329 let local_var_req = local_var_req_builder.build()?;
330 let local_var_resp = local_var_client.execute(local_var_req).await?;
331
332 let local_var_status = local_var_resp.status();
333 let local_var_content = local_var_resp.text().await?;
334
335 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
336 serde_json::from_str(&local_var_content).map_err(Error::from)
337 } else {
338 let local_var_entity: Option<GetAccountError> = local_var_status.try_into().ok();
339 let local_var_error = ResponseContent {
340 status: local_var_status,
341 content: local_var_content,
342 entity: local_var_entity,
343 };
344 Err(Error::ResponseError(local_var_error))
345 }
346}
347
348pub async fn get_account_achievements(
350 configuration: &configuration::Configuration,
351 params: GetAccountAchievementsParams,
352) -> Result<models::DataPageAccountAchievementSchema, Error<GetAccountAchievementsError>> {
353 let local_var_configuration = configuration;
354
355 let account = params.account;
357 let r#type = params.r#type;
359 let completed = params.completed;
361 let page = params.page;
363 let size = params.size;
365
366 let local_var_client = &local_var_configuration.client;
367
368 let local_var_uri_str = format!(
369 "{}/accounts/{account}/achievements",
370 local_var_configuration.base_path,
371 account = crate::apis::urlencode(account)
372 );
373 let mut local_var_req_builder =
374 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
375
376 if let Some(ref local_var_str) = r#type {
377 local_var_req_builder =
378 local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
379 }
380 if let Some(ref local_var_str) = completed {
381 local_var_req_builder =
382 local_var_req_builder.query(&[("completed", &local_var_str.to_string())]);
383 }
384 if let Some(ref local_var_str) = page {
385 local_var_req_builder =
386 local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
387 }
388 if let Some(ref local_var_str) = size {
389 local_var_req_builder =
390 local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
391 }
392 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
393 local_var_req_builder =
394 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
395 }
396
397 let local_var_req = local_var_req_builder.build()?;
398 let local_var_resp = local_var_client.execute(local_var_req).await?;
399
400 let local_var_status = local_var_resp.status();
401 let local_var_content = local_var_resp.text().await?;
402
403 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
404 serde_json::from_str(&local_var_content).map_err(Error::from)
405 } else {
406 let local_var_entity: Option<GetAccountAchievementsError> =
407 local_var_status.try_into().ok();
408 let local_var_error = ResponseContent {
409 status: local_var_status,
410 content: local_var_content,
411 entity: local_var_entity,
412 };
413 Err(Error::ResponseError(local_var_error))
414 }
415}
416
417pub async fn get_account_characters(
419 configuration: &configuration::Configuration,
420 params: GetAccountCharactersParams,
421) -> Result<models::CharactersListSchema, Error<GetAccountCharactersError>> {
422 let local_var_configuration = configuration;
423
424 let account = params.account;
426
427 let local_var_client = &local_var_configuration.client;
428
429 let local_var_uri_str = format!(
430 "{}/accounts/{account}/characters",
431 local_var_configuration.base_path,
432 account = crate::apis::urlencode(account)
433 );
434 let mut local_var_req_builder =
435 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
436
437 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
438 local_var_req_builder =
439 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
440 }
441
442 let local_var_req = local_var_req_builder.build()?;
443 let local_var_resp = local_var_client.execute(local_var_req).await?;
444
445 let local_var_status = local_var_resp.status();
446 let local_var_content = local_var_resp.text().await?;
447
448 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
449 serde_json::from_str(&local_var_content).map_err(Error::from)
450 } else {
451 let local_var_entity: Option<GetAccountCharactersError> = local_var_status.try_into().ok();
452 let local_var_error = ResponseContent {
453 status: local_var_status,
454 content: local_var_content,
455 entity: local_var_entity,
456 };
457 Err(Error::ResponseError(local_var_error))
458 }
459}
460
461pub async fn reset_password(
463 configuration: &configuration::Configuration,
464 params: ResetPasswordParams,
465) -> Result<models::PasswordResetResponseSchema, Error<ResetPasswordError>> {
466 let local_var_configuration = configuration;
467
468 let password_reset_confirm_schema = params.password_reset_confirm_schema;
470
471 let local_var_client = &local_var_configuration.client;
472
473 let local_var_uri_str = format!(
474 "{}/accounts/reset_password",
475 local_var_configuration.base_path
476 );
477 let mut local_var_req_builder =
478 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
479
480 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
481 local_var_req_builder =
482 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
483 }
484 local_var_req_builder = local_var_req_builder.json(&password_reset_confirm_schema);
485
486 let local_var_req = local_var_req_builder.build()?;
487 let local_var_resp = local_var_client.execute(local_var_req).await?;
488
489 let local_var_status = local_var_resp.status();
490 let local_var_content = local_var_resp.text().await?;
491
492 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
493 serde_json::from_str(&local_var_content).map_err(Error::from)
494 } else {
495 let local_var_entity: Option<ResetPasswordError> = local_var_status.try_into().ok();
496 let local_var_error = ResponseContent {
497 status: local_var_status,
498 content: local_var_content,
499 entity: local_var_entity,
500 };
501 Err(Error::ResponseError(local_var_error))
502 }
503}