Skip to main content

artifacts/apis/
npcs_api.rs

1use super::{configuration, Error};
2use crate::{apis::ResponseContent, models};
3use reqwest::StatusCode;
4use serde::{de, Deserialize, Deserializer, Serialize};
5
6/// struct for passing parameters to the method [`get_all_npc_items`]
7#[derive(Clone, Debug)]
8pub struct GetAllNpcItemsParams {
9    /// Item code.
10    pub code: Option<String>,
11    /// NPC code.
12    pub npc: Option<String>,
13    /// Currency code.
14    pub currency: Option<String>,
15    /// Page number
16    pub page: Option<u32>,
17    /// Page size
18    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/// struct for passing parameters to the method [`get_all_npcs`]
40#[derive(Clone, Debug)]
41pub struct GetAllNpcsParams {
42    /// NPC name.
43    pub name: Option<String>,
44    /// Type of NPCs.
45    pub r#type: Option<models::NpcType>,
46    /// Currency code to filter NPCs that trade with this currency.
47    pub currency: Option<String>,
48    /// Item code to filter NPCs that trade this item.
49    pub item: Option<String>,
50    /// Page number
51    pub page: Option<u32>,
52    /// Page size
53    pub size: Option<u32>,
54}
55
56impl GetAllNpcsParams {
57    pub fn new(
58        name: Option<String>,
59        r#type: Option<models::NpcType>,
60        currency: Option<String>,
61        item: Option<String>,
62        page: Option<u32>,
63        size: Option<u32>,
64    ) -> Self {
65        Self {
66            name,
67            r#type,
68            currency,
69            item,
70            page,
71            size,
72        }
73    }
74}
75
76/// struct for passing parameters to the method [`get_npc`]
77#[derive(Clone, Debug)]
78pub struct GetNpcParams {
79    /// The code of the NPC.
80    pub code: String,
81}
82
83impl GetNpcParams {
84    pub fn new(code: String) -> Self {
85        Self { code }
86    }
87}
88
89/// struct for passing parameters to the method [`get_npc_items`]
90#[derive(Clone, Debug)]
91pub struct GetNpcItemsParams {
92    /// The code of the NPC.
93    pub code: String,
94    /// Page number
95    pub page: Option<u32>,
96    /// Page size
97    pub size: Option<u32>,
98}
99
100impl GetNpcItemsParams {
101    pub fn new(code: String, page: Option<u32>, size: Option<u32>) -> Self {
102        Self { code, page, size }
103    }
104}
105
106/// struct for typed errors of method [`get_all_npc_items`]
107#[derive(Debug, Clone, Serialize)]
108#[serde(untagged)]
109pub enum GetAllNpcItemsError {}
110
111impl<'de> Deserialize<'de> for GetAllNpcItemsError {
112    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
113    where
114        D: Deserializer<'de>,
115    {
116        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
117        Err(de::Error::custom(format!(
118            "Unexpected error code: {}",
119            raw.error.code
120        )))
121    }
122}
123
124/// struct for typed errors of method [`get_all_npcs`]
125#[derive(Debug, Clone, Serialize)]
126#[serde(untagged)]
127pub enum GetAllNpcsError {}
128
129impl<'de> Deserialize<'de> for GetAllNpcsError {
130    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
131    where
132        D: Deserializer<'de>,
133    {
134        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
135        Err(de::Error::custom(format!(
136            "Unexpected error code: {}",
137            raw.error.code
138        )))
139    }
140}
141
142/// struct for typed errors of method [`get_npc`]
143#[derive(Debug, Clone, Serialize)]
144#[serde(untagged)]
145pub enum GetNpcError {
146    /// NPC not found.
147    Status404(models::ErrorResponseSchema),
148}
149
150impl<'de> Deserialize<'de> for GetNpcError {
151    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
152    where
153        D: Deserializer<'de>,
154    {
155        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
156        match raw.error.code {
157            404 => Ok(Self::Status404(raw)),
158            _ => Err(de::Error::custom(format!(
159                "Unexpected error code: {}",
160                raw.error.code
161            ))),
162        }
163    }
164}
165
166/// struct for typed errors of method [`get_npc_items`]
167#[derive(Debug, Clone, Serialize)]
168#[serde(untagged)]
169pub enum GetNpcItemsError {
170    /// NPC items not found.
171    Status404(models::ErrorResponseSchema),
172}
173
174impl<'de> Deserialize<'de> for GetNpcItemsError {
175    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
176    where
177        D: Deserializer<'de>,
178    {
179        let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
180        match raw.error.code {
181            404 => Ok(Self::Status404(raw)),
182            _ => Err(de::Error::custom(format!(
183                "Unexpected error code: {}",
184                raw.error.code
185            ))),
186        }
187    }
188}
189
190/// Retrieve the list of all NPC items.
191pub async fn get_all_npc_items(
192    configuration: &configuration::Configuration,
193    params: GetAllNpcItemsParams,
194) -> Result<models::StaticDataPageNpcItem, Error<GetAllNpcItemsError>> {
195    let local_var_configuration = configuration;
196
197    // unbox the parameters
198    let code = params.code;
199    // unbox the parameters
200    let npc = params.npc;
201    // unbox the parameters
202    let currency = params.currency;
203    // unbox the parameters
204    let page = params.page;
205    // unbox the parameters
206    let size = params.size;
207
208    let local_var_client = &local_var_configuration.client;
209
210    let local_var_uri_str = format!("{}/npcs/items", local_var_configuration.base_path);
211    let mut local_var_req_builder =
212        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
213
214    if let Some(ref local_var_str) = code {
215        local_var_req_builder =
216            local_var_req_builder.query(&[("code", &local_var_str.to_string())]);
217    }
218    if let Some(ref local_var_str) = npc {
219        local_var_req_builder = local_var_req_builder.query(&[("npc", &local_var_str.to_string())]);
220    }
221    if let Some(ref local_var_str) = currency {
222        local_var_req_builder =
223            local_var_req_builder.query(&[("currency", &local_var_str.to_string())]);
224    }
225    if let Some(ref local_var_str) = page {
226        local_var_req_builder =
227            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
228    }
229    if let Some(ref local_var_str) = size {
230        local_var_req_builder =
231            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
232    }
233    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
234        local_var_req_builder =
235            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
236    }
237
238    let local_var_req = local_var_req_builder.build()?;
239    let local_var_resp = local_var_client.execute(local_var_req).await?;
240
241    let local_var_status = local_var_resp.status();
242    let local_var_content = local_var_resp.text().await?;
243
244    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
245        serde_json::from_str(&local_var_content).map_err(Error::from)
246    } else {
247        let local_var_entity: Option<GetAllNpcItemsError> =
248            serde_json::from_str(&local_var_content).ok();
249        let local_var_error = ResponseContent {
250            status: local_var_status,
251            content: local_var_content,
252            entity: local_var_entity,
253        };
254        Err(Error::ResponseError(local_var_error))
255    }
256}
257
258/// Fetch NPCs details.
259pub async fn get_all_npcs(
260    configuration: &configuration::Configuration,
261    params: GetAllNpcsParams,
262) -> Result<models::StaticDataPageNpcSchema, Error<GetAllNpcsError>> {
263    let local_var_configuration = configuration;
264
265    // unbox the parameters
266    let name = params.name;
267    // unbox the parameters
268    let r#type = params.r#type;
269    // unbox the parameters
270    let currency = params.currency;
271    // unbox the parameters
272    let item = params.item;
273    // unbox the parameters
274    let page = params.page;
275    // unbox the parameters
276    let size = params.size;
277
278    let local_var_client = &local_var_configuration.client;
279
280    let local_var_uri_str = format!("{}/npcs/details", local_var_configuration.base_path);
281    let mut local_var_req_builder =
282        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
283
284    if let Some(ref local_var_str) = name {
285        local_var_req_builder =
286            local_var_req_builder.query(&[("name", &local_var_str.to_string())]);
287    }
288    if let Some(ref local_var_str) = r#type {
289        local_var_req_builder =
290            local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
291    }
292    if let Some(ref local_var_str) = currency {
293        local_var_req_builder =
294            local_var_req_builder.query(&[("currency", &local_var_str.to_string())]);
295    }
296    if let Some(ref local_var_str) = item {
297        local_var_req_builder =
298            local_var_req_builder.query(&[("item", &local_var_str.to_string())]);
299    }
300    if let Some(ref local_var_str) = page {
301        local_var_req_builder =
302            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
303    }
304    if let Some(ref local_var_str) = size {
305        local_var_req_builder =
306            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
307    }
308    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
309        local_var_req_builder =
310            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
311    }
312
313    let local_var_req = local_var_req_builder.build()?;
314    let local_var_resp = local_var_client.execute(local_var_req).await?;
315
316    let local_var_status = local_var_resp.status();
317    let local_var_content = local_var_resp.text().await?;
318
319    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
320        serde_json::from_str(&local_var_content).map_err(Error::from)
321    } else {
322        let local_var_entity: Option<GetAllNpcsError> =
323            serde_json::from_str(&local_var_content).ok();
324        let local_var_error = ResponseContent {
325            status: local_var_status,
326            content: local_var_content,
327            entity: local_var_entity,
328        };
329        Err(Error::ResponseError(local_var_error))
330    }
331}
332
333/// Retrieve the details of a NPC.
334pub async fn get_npc(
335    configuration: &configuration::Configuration,
336    params: GetNpcParams,
337) -> Result<models::NpcResponseSchema, Error<GetNpcError>> {
338    let local_var_configuration = configuration;
339
340    // unbox the parameters
341    let code = params.code;
342
343    let local_var_client = &local_var_configuration.client;
344
345    let local_var_uri_str = format!(
346        "{}/npcs/details/{code}",
347        local_var_configuration.base_path,
348        code = crate::apis::urlencode(code)
349    );
350    let mut local_var_req_builder =
351        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
352
353    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
354        local_var_req_builder =
355            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
356    }
357
358    let local_var_req = local_var_req_builder.build()?;
359    let local_var_resp = local_var_client.execute(local_var_req).await?;
360
361    let local_var_status = local_var_resp.status();
362    let local_var_content = local_var_resp.text().await?;
363
364    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
365        serde_json::from_str(&local_var_content).map_err(Error::from)
366    } else {
367        let local_var_entity: Option<GetNpcError> = serde_json::from_str(&local_var_content).ok();
368        let local_var_error = ResponseContent {
369            status: local_var_status,
370            content: local_var_content,
371            entity: local_var_entity,
372        };
373        Err(Error::ResponseError(local_var_error))
374    }
375}
376
377/// Retrieve the items list of a NPC. If the NPC has items to buy, sell or trade, they will be displayed.
378pub async fn get_npc_items(
379    configuration: &configuration::Configuration,
380    params: GetNpcItemsParams,
381) -> Result<models::StaticDataPageNpcItem, Error<GetNpcItemsError>> {
382    let local_var_configuration = configuration;
383
384    // unbox the parameters
385    let code = params.code;
386    // unbox the parameters
387    let page = params.page;
388    // unbox the parameters
389    let size = params.size;
390
391    let local_var_client = &local_var_configuration.client;
392
393    let local_var_uri_str = format!(
394        "{}/npcs/items/{code}",
395        local_var_configuration.base_path,
396        code = crate::apis::urlencode(code)
397    );
398    let mut local_var_req_builder =
399        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
400
401    if let Some(ref local_var_str) = page {
402        local_var_req_builder =
403            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
404    }
405    if let Some(ref local_var_str) = size {
406        local_var_req_builder =
407            local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
408    }
409    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
410        local_var_req_builder =
411            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
412    }
413
414    let local_var_req = local_var_req_builder.build()?;
415    let local_var_resp = local_var_client.execute(local_var_req).await?;
416
417    let local_var_status = local_var_resp.status();
418    let local_var_content = local_var_resp.text().await?;
419
420    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
421        serde_json::from_str(&local_var_content).map_err(Error::from)
422    } else {
423        let local_var_entity: Option<GetNpcItemsError> =
424            serde_json::from_str(&local_var_content).ok();
425        let local_var_error = ResponseContent {
426            status: local_var_status,
427            content: local_var_content,
428            entity: local_var_entity,
429        };
430        Err(Error::ResponseError(local_var_error))
431    }
432}