1use super::{configuration, Error};
2use crate::{apis::ResponseContent, models};
3use reqwest::StatusCode;
4use serde::{de, Deserialize, Deserializer, Serialize};
5
6#[derive(Clone, Debug)]
8pub struct CreateCharacterParams {
9 pub add_character_schema: models::AddCharacterSchema,
10}
11
12impl CreateCharacterParams {
13 pub fn new(add_character_schema: models::AddCharacterSchema) -> Self {
14 Self {
15 add_character_schema,
16 }
17 }
18}
19
20#[derive(Clone, Debug)]
22pub struct DeleteCharacterParams {
23 pub delete_character_schema: models::DeleteCharacterSchema,
24}
25
26impl DeleteCharacterParams {
27 pub fn new(delete_character_schema: models::DeleteCharacterSchema) -> Self {
28 Self {
29 delete_character_schema,
30 }
31 }
32}
33
34#[derive(Clone, Debug)]
36pub struct GetActiveCharactersParams {
37 pub page: Option<u32>,
39 pub size: Option<u32>,
41}
42
43impl GetActiveCharactersParams {
44 pub fn new(page: Option<u32>, size: Option<u32>) -> Self {
45 Self { page, size }
46 }
47}
48
49#[derive(Clone, Debug)]
51pub struct GetCharacterParams {
52 pub name: String,
54}
55
56impl GetCharacterParams {
57 pub fn new(name: String) -> Self {
58 Self { name }
59 }
60}
61
62#[derive(Debug, Clone, Serialize)]
64#[serde(untagged)]
65pub enum CreateCharacterError {
66 Status494(models::ErrorResponseSchema),
68 Status495(models::ErrorResponseSchema),
70 Status550(models::ErrorResponseSchema),
72 Status422(models::ErrorResponseSchema),
74}
75
76impl<'de> Deserialize<'de> for CreateCharacterError {
77 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
78 where
79 D: Deserializer<'de>,
80 {
81 let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
82 match raw.error.code {
83 494 => Ok(Self::Status494(raw)),
84 495 => Ok(Self::Status495(raw)),
85 550 => Ok(Self::Status550(raw)),
86 422 => Ok(Self::Status422(raw)),
87 _ => Err(de::Error::custom(format!(
88 "Unexpected error code: {}",
89 raw.error.code
90 ))),
91 }
92 }
93}
94
95#[derive(Debug, Clone, Serialize)]
97#[serde(untagged)]
98pub enum DeleteCharacterError {
99 Status498(models::ErrorResponseSchema),
101 Status422(models::ErrorResponseSchema),
103}
104
105impl<'de> Deserialize<'de> for DeleteCharacterError {
106 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
107 where
108 D: Deserializer<'de>,
109 {
110 let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
111 match raw.error.code {
112 498 => Ok(Self::Status498(raw)),
113 422 => Ok(Self::Status422(raw)),
114 _ => Err(de::Error::custom(format!(
115 "Unexpected error code: {}",
116 raw.error.code
117 ))),
118 }
119 }
120}
121
122#[derive(Debug, Clone, Serialize)]
124#[serde(untagged)]
125pub enum GetActiveCharactersError {}
126
127impl<'de> Deserialize<'de> for GetActiveCharactersError {
128 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
129 where
130 D: Deserializer<'de>,
131 {
132 let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
133 Err(de::Error::custom(format!(
134 "Unexpected error code: {}",
135 raw.error.code
136 )))
137 }
138}
139
140#[derive(Debug, Clone, Serialize)]
142#[serde(untagged)]
143pub enum GetCharacterError {
144 Status404(models::ErrorResponseSchema),
146}
147
148impl<'de> Deserialize<'de> for GetCharacterError {
149 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
150 where
151 D: Deserializer<'de>,
152 {
153 let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
154 match raw.error.code {
155 404 => Ok(Self::Status404(raw)),
156 _ => Err(de::Error::custom(format!(
157 "Unexpected error code: {}",
158 raw.error.code
159 ))),
160 }
161 }
162}
163
164pub async fn create_character(
166 configuration: &configuration::Configuration,
167 params: CreateCharacterParams,
168) -> Result<models::CharacterResponseSchema, Error<CreateCharacterError>> {
169 let local_var_configuration = configuration;
170
171 let add_character_schema = params.add_character_schema;
173
174 let local_var_client = &local_var_configuration.client;
175
176 let local_var_uri_str = format!("{}/characters/create", local_var_configuration.base_path);
177 let mut local_var_req_builder =
178 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
179
180 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
181 local_var_req_builder =
182 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
183 }
184 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
185 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
186 };
187 local_var_req_builder = local_var_req_builder.json(&add_character_schema);
188
189 let local_var_req = local_var_req_builder.build()?;
190 let local_var_resp = local_var_client.execute(local_var_req).await?;
191
192 let local_var_status = local_var_resp.status();
193 let local_var_content = local_var_resp.text().await?;
194
195 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
196 serde_json::from_str(&local_var_content).map_err(Error::from)
197 } else {
198 let local_var_entity: Option<CreateCharacterError> =
199 serde_json::from_str(&local_var_content).ok();
200 let local_var_error = ResponseContent {
201 status: local_var_status,
202 content: local_var_content,
203 entity: local_var_entity,
204 };
205 Err(Error::ResponseError(local_var_error))
206 }
207}
208
209pub async fn delete_character(
211 configuration: &configuration::Configuration,
212 params: DeleteCharacterParams,
213) -> Result<models::CharacterResponseSchema, Error<DeleteCharacterError>> {
214 let local_var_configuration = configuration;
215
216 let delete_character_schema = params.delete_character_schema;
218
219 let local_var_client = &local_var_configuration.client;
220
221 let local_var_uri_str = format!("{}/characters/delete", local_var_configuration.base_path);
222 let mut local_var_req_builder =
223 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
224
225 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
226 local_var_req_builder =
227 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
228 }
229 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
230 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
231 };
232 local_var_req_builder = local_var_req_builder.json(&delete_character_schema);
233
234 let local_var_req = local_var_req_builder.build()?;
235 let local_var_resp = local_var_client.execute(local_var_req).await?;
236
237 let local_var_status = local_var_resp.status();
238 let local_var_content = local_var_resp.text().await?;
239
240 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
241 serde_json::from_str(&local_var_content).map_err(Error::from)
242 } else {
243 let local_var_entity: Option<DeleteCharacterError> =
244 serde_json::from_str(&local_var_content).ok();
245 let local_var_error = ResponseContent {
246 status: local_var_status,
247 content: local_var_content,
248 entity: local_var_entity,
249 };
250 Err(Error::ResponseError(local_var_error))
251 }
252}
253
254pub async fn get_active_characters(
256 configuration: &configuration::Configuration,
257 params: GetActiveCharactersParams,
258) -> Result<models::DataPageActiveCharacterSchema, Error<GetActiveCharactersError>> {
259 let local_var_configuration = configuration;
260
261 let page = params.page;
263 let size = params.size;
265
266 let local_var_client = &local_var_configuration.client;
267
268 let local_var_uri_str = format!("{}/characters/active", local_var_configuration.base_path);
269 let mut local_var_req_builder =
270 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
271
272 if let Some(ref local_var_str) = page {
273 local_var_req_builder =
274 local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
275 }
276 if let Some(ref local_var_str) = size {
277 local_var_req_builder =
278 local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
279 }
280 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
281 local_var_req_builder =
282 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
283 }
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<GetActiveCharactersError> =
295 serde_json::from_str(&local_var_content).ok();
296 let local_var_error = ResponseContent {
297 status: local_var_status,
298 content: local_var_content,
299 entity: local_var_entity,
300 };
301 Err(Error::ResponseError(local_var_error))
302 }
303}
304
305pub async fn get_character(
307 configuration: &configuration::Configuration,
308 params: GetCharacterParams,
309) -> Result<models::CharacterResponseSchema, Error<GetCharacterError>> {
310 let local_var_configuration = configuration;
311
312 let name = params.name;
314
315 let local_var_client = &local_var_configuration.client;
316
317 let local_var_uri_str = format!(
318 "{}/characters/{name}",
319 local_var_configuration.base_path,
320 name = crate::apis::urlencode(name)
321 );
322 let mut local_var_req_builder =
323 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
324
325 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
326 local_var_req_builder =
327 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
328 }
329
330 let local_var_req = local_var_req_builder.build()?;
331 let local_var_resp = local_var_client.execute(local_var_req).await?;
332
333 let local_var_status = local_var_resp.status();
334 let local_var_content = local_var_resp.text().await?;
335
336 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
337 serde_json::from_str(&local_var_content).map_err(Error::from)
338 } else {
339 let local_var_entity: Option<GetCharacterError> =
340 serde_json::from_str(&local_var_content).ok();
341 let local_var_error = ResponseContent {
342 status: local_var_status,
343 content: local_var_content,
344 entity: local_var_entity,
345 };
346 Err(Error::ResponseError(local_var_error))
347 }
348}