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