artifacts/apis/
npcs_api.rs

1use super::{configuration, Error};
2use crate::{apis::ResponseContent, models};
3use reqwest::StatusCode;
4use serde::{Deserialize, Serialize};
5
6/// struct for passing parameters to the method [`get_all_npc_items`]
7#[derive(Clone, Debug)]
8pub struct GetAllNpcItemsParams {
9    /// The code of the item.
10    pub code: Option<String>,
11    /// The code of the npc.
12    pub npc: Option<String>,
13    /// The code of the currency.
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    /// Name of the npc.
43    pub name: Option<String>,
44    /// The type of the NPC.
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, 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/// struct for typed errors of method [`get_all_npcs`]
114#[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/// struct for typed errors of method [`get_npc`]
129#[derive(Debug, Clone, Serialize, Deserialize)]
130#[serde(untagged)]
131pub enum GetNpcError {
132    /// NPC not found.
133    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/// struct for typed errors of method [`get_npc_items`]
148#[derive(Debug, Clone, Serialize, Deserialize)]
149#[serde(untagged)]
150pub enum GetNpcItemsError {
151    /// NPC not found.
152    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
166/// Retrieve the list of all NPC items.
167pub 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    // unbox the parameters
174    let code = params.code;
175    // unbox the parameters
176    let npc = params.npc;
177    // unbox the parameters
178    let currency = params.currency;
179    // unbox the parameters
180    let page = params.page;
181    // unbox the parameters
182    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
233/// Fetch NPCs details.
234pub 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    // unbox the parameters
241    let name = params.name;
242    // unbox the parameters
243    let r#type = params.r#type;
244    // unbox the parameters
245    let page = params.page;
246    // unbox the parameters
247    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
295/// Retrieve the details of a NPC.
296pub 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    // unbox the parameters
303    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
339/// Retrieve the items list of a NPC. If the NPC has items to buy, sell or trade, they will be displayed.
340pub 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    // unbox the parameters
347    let code = params.code;
348    // unbox the parameters
349    let page = params.page;
350    // unbox the parameters
351    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}