use super::{configuration, Error};
use crate::{apis::ResponseContent, models};
use reqwest::StatusCode;
use serde::{de, Deserialize, Deserializer, Serialize};
#[derive(Clone, Debug)]
pub struct GetAllMapsParams {
pub layer: Option<models::MapLayer>,
pub content_type: Option<models::MapContentType>,
pub content_code: Option<String>,
pub hide_blocked_maps: Option<bool>,
pub page: Option<u32>,
pub size: Option<u32>,
}
impl GetAllMapsParams {
pub fn new(
layer: Option<models::MapLayer>,
content_type: Option<models::MapContentType>,
content_code: Option<String>,
hide_blocked_maps: Option<bool>,
page: Option<u32>,
size: Option<u32>,
) -> Self {
Self {
layer,
content_type,
content_code,
hide_blocked_maps,
page,
size,
}
}
}
#[derive(Clone, Debug)]
pub struct GetLayerMapsParams {
pub layer: String,
pub content_type: Option<String>,
pub content_code: Option<String>,
pub hide_blocked_maps: Option<bool>,
pub page: Option<u32>,
pub size: Option<u32>,
}
impl GetLayerMapsParams {
pub fn new(
layer: String,
content_type: Option<String>,
content_code: Option<String>,
hide_blocked_maps: Option<bool>,
page: Option<u32>,
size: Option<u32>,
) -> Self {
Self {
layer,
content_type,
content_code,
hide_blocked_maps,
page,
size,
}
}
}
#[derive(Clone, Debug)]
pub struct GetMapByIdParams {
pub map_id: i32,
}
impl GetMapByIdParams {
pub fn new(map_id: i32) -> Self {
Self { map_id }
}
}
#[derive(Clone, Debug)]
pub struct GetMapByPositionParams {
pub layer: String,
pub x: i32,
pub y: i32,
}
impl GetMapByPositionParams {
pub fn new(layer: String, x: i32, y: i32) -> Self {
Self { layer, x, y }
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum GetAllMapsError {}
impl<'de> Deserialize<'de> for GetAllMapsError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
Err(de::Error::custom(format!(
"Unexpected error code: {}",
raw.error.code
)))
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum GetLayerMapsError {}
impl<'de> Deserialize<'de> for GetLayerMapsError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
Err(de::Error::custom(format!(
"Unexpected error code: {}",
raw.error.code
)))
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum GetMapByIdError {
Status404(models::ErrorResponseSchema),
}
impl<'de> Deserialize<'de> for GetMapByIdError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
match raw.error.code {
404 => Ok(Self::Status404(raw)),
_ => Err(de::Error::custom(format!(
"Unexpected error code: {}",
raw.error.code
))),
}
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum GetMapByPositionError {
Status404(models::ErrorResponseSchema),
}
impl<'de> Deserialize<'de> for GetMapByPositionError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
match raw.error.code {
404 => Ok(Self::Status404(raw)),
_ => Err(de::Error::custom(format!(
"Unexpected error code: {}",
raw.error.code
))),
}
}
}
pub async fn get_all_maps(
configuration: &configuration::Configuration,
params: GetAllMapsParams,
) -> Result<models::DataPageMapSchema, Error<GetAllMapsError>> {
let local_var_configuration = configuration;
let layer = params.layer;
let content_type = params.content_type;
let content_code = params.content_code;
let hide_blocked_maps = params.hide_blocked_maps;
let page = params.page;
let size = params.size;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/maps", local_var_configuration.base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = layer {
local_var_req_builder =
local_var_req_builder.query(&[("layer", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = content_type {
local_var_req_builder =
local_var_req_builder.query(&[("content_type", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = content_code {
local_var_req_builder =
local_var_req_builder.query(&[("content_code", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = hide_blocked_maps {
local_var_req_builder =
local_var_req_builder.query(&[("hide_blocked_maps", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = page {
local_var_req_builder =
local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = size {
local_var_req_builder =
local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetAllMapsError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_layer_maps(
configuration: &configuration::Configuration,
params: GetLayerMapsParams,
) -> Result<models::DataPageMapSchema, Error<GetLayerMapsError>> {
let local_var_configuration = configuration;
let layer = params.layer;
let content_type = params.content_type;
let content_code = params.content_code;
let hide_blocked_maps = params.hide_blocked_maps;
let page = params.page;
let size = params.size;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/maps/{layer}",
local_var_configuration.base_path,
layer = layer
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = content_type {
local_var_req_builder =
local_var_req_builder.query(&[("content_type", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = content_code {
local_var_req_builder =
local_var_req_builder.query(&[("content_code", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = hide_blocked_maps {
local_var_req_builder =
local_var_req_builder.query(&[("hide_blocked_maps", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = page {
local_var_req_builder =
local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = size {
local_var_req_builder =
local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetLayerMapsError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_map_by_id(
configuration: &configuration::Configuration,
params: GetMapByIdParams,
) -> Result<models::MapResponseSchema, Error<GetMapByIdError>> {
let local_var_configuration = configuration;
let map_id = params.map_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/maps/id/{map_id}",
local_var_configuration.base_path,
map_id = map_id
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetMapByIdError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_map_by_position(
configuration: &configuration::Configuration,
params: GetMapByPositionParams,
) -> Result<models::MapResponseSchema, Error<GetMapByPositionError>> {
let local_var_configuration = configuration;
let layer = params.layer;
let x = params.x;
let y = params.y;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/maps/{layer}/{x}/{y}",
local_var_configuration.base_path,
layer = layer,
x = x,
y = y
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetMapByPositionError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}