1use super::{configuration, Error};
2use crate::{apis::ResponseContent, models};
3use reqwest::StatusCode;
4use serde::{Deserialize, Serialize};
5
6#[derive(Clone, Debug)]
8pub struct GetAllNpcItemsParams {
9 pub code: Option<String>,
11 pub npc: Option<String>,
13 pub currency: Option<String>,
15 pub page: Option<u32>,
17 pub size: Option<u32>,
19}
20
21impl GetAllNpcItemsParams {
22 pub fn new(
23 code: Option<String>,
24 npc: Option<String>,
25 currency: Option<String>,
26 page: Option<u32>,
27 size: Option<u32>,
28 ) -> Self {
29 Self {
30 code,
31 npc,
32 currency,
33 page,
34 size,
35 }
36 }
37}
38
39#[derive(Clone, Debug)]
41pub struct GetAllNpcsParams {
42 pub name: Option<String>,
44 pub r#type: Option<models::NpcType>,
46 pub page: Option<u32>,
48 pub size: Option<u32>,
50}
51
52impl GetAllNpcsParams {
53 pub fn new(
54 name: Option<String>,
55 r#type: Option<models::NpcType>,
56 page: Option<u32>,
57 size: Option<u32>,
58 ) -> Self {
59 Self {
60 name,
61 r#type,
62 page,
63 size,
64 }
65 }
66}
67
68#[derive(Clone, Debug)]
70pub struct GetNpcParams {
71 pub code: String,
73}
74
75impl GetNpcParams {
76 pub fn new(code: String) -> Self {
77 Self { code }
78 }
79}
80
81#[derive(Clone, Debug)]
83pub struct GetNpcItemsParams {
84 pub code: String,
86 pub page: Option<u32>,
88 pub size: Option<u32>,
90}
91
92impl GetNpcItemsParams {
93 pub fn new(code: String, page: Option<u32>, size: Option<u32>) -> Self {
94 Self { code, page, size }
95 }
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(untagged)]
101pub enum GetAllNpcItemsError {}
102
103impl TryFrom<StatusCode> for GetAllNpcItemsError {
104 type Error = &'static str;
105 #[allow(clippy::match_single_binding)]
106 fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
107 match status.as_u16() {
108 _ => Err("status code not in spec"),
109 }
110 }
111}
112
113#[derive(Debug, Clone, Serialize, Deserialize)]
115#[serde(untagged)]
116pub enum GetAllNpcsError {}
117
118impl TryFrom<StatusCode> for GetAllNpcsError {
119 type Error = &'static str;
120 #[allow(clippy::match_single_binding)]
121 fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
122 match status.as_u16() {
123 _ => Err("status code not in spec"),
124 }
125 }
126}
127
128#[derive(Debug, Clone, Serialize, Deserialize)]
130#[serde(untagged)]
131pub enum GetNpcError {
132 Status404,
134}
135
136impl TryFrom<StatusCode> for GetNpcError {
137 type Error = &'static str;
138 #[allow(clippy::match_single_binding)]
139 fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
140 match status.as_u16() {
141 404 => Ok(Self::Status404),
142 _ => Err("status code not in spec"),
143 }
144 }
145}
146
147#[derive(Debug, Clone, Serialize, Deserialize)]
149#[serde(untagged)]
150pub enum GetNpcItemsError {
151 Status404,
153}
154
155impl TryFrom<StatusCode> for GetNpcItemsError {
156 type Error = &'static str;
157 #[allow(clippy::match_single_binding)]
158 fn try_from(status: StatusCode) -> Result<Self, Self::Error> {
159 match status.as_u16() {
160 404 => Ok(Self::Status404),
161 _ => Err("status code not in spec"),
162 }
163 }
164}
165
166pub async fn get_all_npc_items(
168 configuration: &configuration::Configuration,
169 params: GetAllNpcItemsParams,
170) -> Result<models::DataPageNpcItem, Error<GetAllNpcItemsError>> {
171 let local_var_configuration = configuration;
172
173 let code = params.code;
175 let npc = params.npc;
177 let currency = params.currency;
179 let page = params.page;
181 let size = params.size;
183
184 let local_var_client = &local_var_configuration.client;
185
186 let local_var_uri_str = format!("{}/npcs/items", local_var_configuration.base_path);
187 let mut local_var_req_builder =
188 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
189
190 if let Some(ref local_var_str) = code {
191 local_var_req_builder =
192 local_var_req_builder.query(&[("code", &local_var_str.to_string())]);
193 }
194 if let Some(ref local_var_str) = npc {
195 local_var_req_builder = local_var_req_builder.query(&[("npc", &local_var_str.to_string())]);
196 }
197 if let Some(ref local_var_str) = currency {
198 local_var_req_builder =
199 local_var_req_builder.query(&[("currency", &local_var_str.to_string())]);
200 }
201 if let Some(ref local_var_str) = page {
202 local_var_req_builder =
203 local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
204 }
205 if let Some(ref local_var_str) = size {
206 local_var_req_builder =
207 local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
208 }
209 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
210 local_var_req_builder =
211 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
212 }
213
214 let local_var_req = local_var_req_builder.build()?;
215 let local_var_resp = local_var_client.execute(local_var_req).await?;
216
217 let local_var_status = local_var_resp.status();
218 let local_var_content = local_var_resp.text().await?;
219
220 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
221 serde_json::from_str(&local_var_content).map_err(Error::from)
222 } else {
223 let local_var_entity: Option<GetAllNpcItemsError> = local_var_status.try_into().ok();
224 let local_var_error = ResponseContent {
225 status: local_var_status,
226 content: local_var_content,
227 entity: local_var_entity,
228 };
229 Err(Error::ResponseError(local_var_error))
230 }
231}
232
233pub async fn get_all_npcs(
235 configuration: &configuration::Configuration,
236 params: GetAllNpcsParams,
237) -> Result<models::DataPageNpcSchema, Error<GetAllNpcsError>> {
238 let local_var_configuration = configuration;
239
240 let name = params.name;
242 let r#type = params.r#type;
244 let page = params.page;
246 let size = params.size;
248
249 let local_var_client = &local_var_configuration.client;
250
251 let local_var_uri_str = format!("{}/npcs/details", local_var_configuration.base_path);
252 let mut local_var_req_builder =
253 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
254
255 if let Some(ref local_var_str) = name {
256 local_var_req_builder =
257 local_var_req_builder.query(&[("name", &local_var_str.to_string())]);
258 }
259 if let Some(ref local_var_str) = r#type {
260 local_var_req_builder =
261 local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
262 }
263 if let Some(ref local_var_str) = page {
264 local_var_req_builder =
265 local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
266 }
267 if let Some(ref local_var_str) = size {
268 local_var_req_builder =
269 local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
270 }
271 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
272 local_var_req_builder =
273 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
274 }
275
276 let local_var_req = local_var_req_builder.build()?;
277 let local_var_resp = local_var_client.execute(local_var_req).await?;
278
279 let local_var_status = local_var_resp.status();
280 let local_var_content = local_var_resp.text().await?;
281
282 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
283 serde_json::from_str(&local_var_content).map_err(Error::from)
284 } else {
285 let local_var_entity: Option<GetAllNpcsError> = local_var_status.try_into().ok();
286 let local_var_error = ResponseContent {
287 status: local_var_status,
288 content: local_var_content,
289 entity: local_var_entity,
290 };
291 Err(Error::ResponseError(local_var_error))
292 }
293}
294
295pub async fn get_npc(
297 configuration: &configuration::Configuration,
298 params: GetNpcParams,
299) -> Result<models::NpcResponseSchema, Error<GetNpcError>> {
300 let local_var_configuration = configuration;
301
302 let code = params.code;
304
305 let local_var_client = &local_var_configuration.client;
306
307 let local_var_uri_str = format!(
308 "{}/npcs/details/{code}",
309 local_var_configuration.base_path,
310 code = crate::apis::urlencode(code)
311 );
312 let mut local_var_req_builder =
313 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
314
315 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
316 local_var_req_builder =
317 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
318 }
319
320 let local_var_req = local_var_req_builder.build()?;
321 let local_var_resp = local_var_client.execute(local_var_req).await?;
322
323 let local_var_status = local_var_resp.status();
324 let local_var_content = local_var_resp.text().await?;
325
326 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
327 serde_json::from_str(&local_var_content).map_err(Error::from)
328 } else {
329 let local_var_entity: Option<GetNpcError> = local_var_status.try_into().ok();
330 let local_var_error = ResponseContent {
331 status: local_var_status,
332 content: local_var_content,
333 entity: local_var_entity,
334 };
335 Err(Error::ResponseError(local_var_error))
336 }
337}
338
339pub async fn get_npc_items(
341 configuration: &configuration::Configuration,
342 params: GetNpcItemsParams,
343) -> Result<models::DataPageNpcItem, Error<GetNpcItemsError>> {
344 let local_var_configuration = configuration;
345
346 let code = params.code;
348 let page = params.page;
350 let size = params.size;
352
353 let local_var_client = &local_var_configuration.client;
354
355 let local_var_uri_str = format!(
356 "{}/npcs/items/{code}",
357 local_var_configuration.base_path,
358 code = crate::apis::urlencode(code)
359 );
360 let mut local_var_req_builder =
361 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
362
363 if let Some(ref local_var_str) = page {
364 local_var_req_builder =
365 local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
366 }
367 if let Some(ref local_var_str) = size {
368 local_var_req_builder =
369 local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
370 }
371 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
372 local_var_req_builder =
373 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
374 }
375
376 let local_var_req = local_var_req_builder.build()?;
377 let local_var_resp = local_var_client.execute(local_var_req).await?;
378
379 let local_var_status = local_var_resp.status();
380 let local_var_content = local_var_resp.text().await?;
381
382 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
383 serde_json::from_str(&local_var_content).map_err(Error::from)
384 } else {
385 let local_var_entity: Option<GetNpcItemsError> = local_var_status.try_into().ok();
386 let local_var_error = ResponseContent {
387 status: local_var_status,
388 content: local_var_content,
389 entity: local_var_entity,
390 };
391 Err(Error::ResponseError(local_var_error))
392 }
393}