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 GetAllMapsParams {
9 pub layer: Option<models::MapLayer>,
11 pub content_type: Option<models::MapContentType>,
13 pub content_code: Option<String>,
15 pub hide_blocked_maps: Option<bool>,
17 pub page: Option<u32>,
19 pub size: Option<u32>,
21}
22
23impl GetAllMapsParams {
24 pub fn new(
25 layer: Option<models::MapLayer>,
26 content_type: Option<models::MapContentType>,
27 content_code: Option<String>,
28 hide_blocked_maps: Option<bool>,
29 page: Option<u32>,
30 size: Option<u32>,
31 ) -> Self {
32 Self {
33 layer,
34 content_type,
35 content_code,
36 hide_blocked_maps,
37 page,
38 size,
39 }
40 }
41}
42
43#[derive(Clone, Debug)]
45pub struct GetLayerMapsParams {
46 pub layer: String,
48 pub content_type: Option<String>,
50 pub content_code: Option<String>,
52 pub hide_blocked_maps: Option<bool>,
54 pub page: Option<u32>,
56 pub size: Option<u32>,
58}
59
60impl GetLayerMapsParams {
61 pub fn new(
62 layer: String,
63 content_type: Option<String>,
64 content_code: Option<String>,
65 hide_blocked_maps: Option<bool>,
66 page: Option<u32>,
67 size: Option<u32>,
68 ) -> Self {
69 Self {
70 layer,
71 content_type,
72 content_code,
73 hide_blocked_maps,
74 page,
75 size,
76 }
77 }
78}
79
80#[derive(Clone, Debug)]
82pub struct GetMapByIdParams {
83 pub map_id: i32,
85}
86
87impl GetMapByIdParams {
88 pub fn new(map_id: i32) -> Self {
89 Self { map_id }
90 }
91}
92
93#[derive(Clone, Debug)]
95pub struct GetMapByPositionParams {
96 pub layer: String,
98 pub x: i32,
100 pub y: i32,
102}
103
104impl GetMapByPositionParams {
105 pub fn new(layer: String, x: i32, y: i32) -> Self {
106 Self { layer, x, y }
107 }
108}
109
110#[derive(Debug, Clone, Serialize)]
112#[serde(untagged)]
113pub enum GetAllMapsError {}
114
115impl<'de> Deserialize<'de> for GetAllMapsError {
116 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
117 where
118 D: Deserializer<'de>,
119 {
120 let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
121 Err(de::Error::custom(format!(
122 "Unexpected error code: {}",
123 raw.error.code
124 )))
125 }
126}
127
128#[derive(Debug, Clone, Serialize)]
130#[serde(untagged)]
131pub enum GetLayerMapsError {}
132
133impl<'de> Deserialize<'de> for GetLayerMapsError {
134 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
135 where
136 D: Deserializer<'de>,
137 {
138 let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
139 Err(de::Error::custom(format!(
140 "Unexpected error code: {}",
141 raw.error.code
142 )))
143 }
144}
145
146#[derive(Debug, Clone, Serialize)]
148#[serde(untagged)]
149pub enum GetMapByIdError {
150 Status404(models::ErrorResponseSchema),
152}
153
154impl<'de> Deserialize<'de> for GetMapByIdError {
155 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
156 where
157 D: Deserializer<'de>,
158 {
159 let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
160 match raw.error.code {
161 404 => Ok(Self::Status404(raw)),
162 _ => Err(de::Error::custom(format!(
163 "Unexpected error code: {}",
164 raw.error.code
165 ))),
166 }
167 }
168}
169
170#[derive(Debug, Clone, Serialize)]
172#[serde(untagged)]
173pub enum GetMapByPositionError {
174 Status404(models::ErrorResponseSchema),
176}
177
178impl<'de> Deserialize<'de> for GetMapByPositionError {
179 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
180 where
181 D: Deserializer<'de>,
182 {
183 let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
184 match raw.error.code {
185 404 => Ok(Self::Status404(raw)),
186 _ => Err(de::Error::custom(format!(
187 "Unexpected error code: {}",
188 raw.error.code
189 ))),
190 }
191 }
192}
193
194pub async fn get_all_maps(
196 configuration: &configuration::Configuration,
197 params: GetAllMapsParams,
198) -> Result<models::DataPageMapSchema, Error<GetAllMapsError>> {
199 let local_var_configuration = configuration;
200
201 let layer = params.layer;
203 let content_type = params.content_type;
205 let content_code = params.content_code;
207 let hide_blocked_maps = params.hide_blocked_maps;
209 let page = params.page;
211 let size = params.size;
213
214 let local_var_client = &local_var_configuration.client;
215
216 let local_var_uri_str = format!("{}/maps", local_var_configuration.base_path);
217 let mut local_var_req_builder =
218 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
219
220 if let Some(ref local_var_str) = layer {
221 local_var_req_builder =
222 local_var_req_builder.query(&[("layer", &local_var_str.to_string())]);
223 }
224 if let Some(ref local_var_str) = content_type {
225 local_var_req_builder =
226 local_var_req_builder.query(&[("content_type", &local_var_str.to_string())]);
227 }
228 if let Some(ref local_var_str) = content_code {
229 local_var_req_builder =
230 local_var_req_builder.query(&[("content_code", &local_var_str.to_string())]);
231 }
232 if let Some(ref local_var_str) = hide_blocked_maps {
233 local_var_req_builder =
234 local_var_req_builder.query(&[("hide_blocked_maps", &local_var_str.to_string())]);
235 }
236 if let Some(ref local_var_str) = page {
237 local_var_req_builder =
238 local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
239 }
240 if let Some(ref local_var_str) = size {
241 local_var_req_builder =
242 local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
243 }
244 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
245 local_var_req_builder =
246 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
247 }
248
249 let local_var_req = local_var_req_builder.build()?;
250 let local_var_resp = local_var_client.execute(local_var_req).await?;
251
252 let local_var_status = local_var_resp.status();
253 let local_var_content = local_var_resp.text().await?;
254
255 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
256 serde_json::from_str(&local_var_content).map_err(Error::from)
257 } else {
258 let local_var_entity: Option<GetAllMapsError> =
259 serde_json::from_str(&local_var_content).ok();
260 let local_var_error = ResponseContent {
261 status: local_var_status,
262 content: local_var_content,
263 entity: local_var_entity,
264 };
265 Err(Error::ResponseError(local_var_error))
266 }
267}
268
269pub async fn get_layer_maps(
271 configuration: &configuration::Configuration,
272 params: GetLayerMapsParams,
273) -> Result<models::DataPageMapSchema, Error<GetLayerMapsError>> {
274 let local_var_configuration = configuration;
275
276 let layer = params.layer;
278 let content_type = params.content_type;
280 let content_code = params.content_code;
282 let hide_blocked_maps = params.hide_blocked_maps;
284 let page = params.page;
286 let size = params.size;
288
289 let local_var_client = &local_var_configuration.client;
290
291 let local_var_uri_str = format!(
292 "{}/maps/{layer}",
293 local_var_configuration.base_path,
294 layer = layer
295 );
296 let mut local_var_req_builder =
297 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
298
299 if let Some(ref local_var_str) = content_type {
300 local_var_req_builder =
301 local_var_req_builder.query(&[("content_type", &local_var_str.to_string())]);
302 }
303 if let Some(ref local_var_str) = content_code {
304 local_var_req_builder =
305 local_var_req_builder.query(&[("content_code", &local_var_str.to_string())]);
306 }
307 if let Some(ref local_var_str) = hide_blocked_maps {
308 local_var_req_builder =
309 local_var_req_builder.query(&[("hide_blocked_maps", &local_var_str.to_string())]);
310 }
311 if let Some(ref local_var_str) = page {
312 local_var_req_builder =
313 local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
314 }
315 if let Some(ref local_var_str) = size {
316 local_var_req_builder =
317 local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
318 }
319 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
320 local_var_req_builder =
321 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
322 }
323
324 let local_var_req = local_var_req_builder.build()?;
325 let local_var_resp = local_var_client.execute(local_var_req).await?;
326
327 let local_var_status = local_var_resp.status();
328 let local_var_content = local_var_resp.text().await?;
329
330 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
331 serde_json::from_str(&local_var_content).map_err(Error::from)
332 } else {
333 let local_var_entity: Option<GetLayerMapsError> =
334 serde_json::from_str(&local_var_content).ok();
335 let local_var_error = ResponseContent {
336 status: local_var_status,
337 content: local_var_content,
338 entity: local_var_entity,
339 };
340 Err(Error::ResponseError(local_var_error))
341 }
342}
343
344pub async fn get_map_by_id(
346 configuration: &configuration::Configuration,
347 params: GetMapByIdParams,
348) -> Result<models::MapResponseSchema, Error<GetMapByIdError>> {
349 let local_var_configuration = configuration;
350
351 let map_id = params.map_id;
353
354 let local_var_client = &local_var_configuration.client;
355
356 let local_var_uri_str = format!(
357 "{}/maps/id/{map_id}",
358 local_var_configuration.base_path,
359 map_id = map_id
360 );
361 let mut local_var_req_builder =
362 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
363
364 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
365 local_var_req_builder =
366 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
367 }
368
369 let local_var_req = local_var_req_builder.build()?;
370 let local_var_resp = local_var_client.execute(local_var_req).await?;
371
372 let local_var_status = local_var_resp.status();
373 let local_var_content = local_var_resp.text().await?;
374
375 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
376 serde_json::from_str(&local_var_content).map_err(Error::from)
377 } else {
378 let local_var_entity: Option<GetMapByIdError> =
379 serde_json::from_str(&local_var_content).ok();
380 let local_var_error = ResponseContent {
381 status: local_var_status,
382 content: local_var_content,
383 entity: local_var_entity,
384 };
385 Err(Error::ResponseError(local_var_error))
386 }
387}
388
389pub async fn get_map_by_position(
391 configuration: &configuration::Configuration,
392 params: GetMapByPositionParams,
393) -> Result<models::MapResponseSchema, Error<GetMapByPositionError>> {
394 let local_var_configuration = configuration;
395
396 let layer = params.layer;
398 let x = params.x;
400 let y = params.y;
402
403 let local_var_client = &local_var_configuration.client;
404
405 let local_var_uri_str = format!(
406 "{}/maps/{layer}/{x}/{y}",
407 local_var_configuration.base_path,
408 layer = layer,
409 x = x,
410 y = y
411 );
412 let mut local_var_req_builder =
413 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
414
415 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
416 local_var_req_builder =
417 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
418 }
419
420 let local_var_req = local_var_req_builder.build()?;
421 let local_var_resp = local_var_client.execute(local_var_req).await?;
422
423 let local_var_status = local_var_resp.status();
424 let local_var_content = local_var_resp.text().await?;
425
426 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
427 serde_json::from_str(&local_var_content).map_err(Error::from)
428 } else {
429 let local_var_entity: Option<GetMapByPositionError> =
430 serde_json::from_str(&local_var_content).ok();
431 let local_var_error = ResponseContent {
432 status: local_var_status,
433 content: local_var_content,
434 entity: local_var_entity,
435 };
436 Err(Error::ResponseError(local_var_error))
437 }
438}