use super::{configuration, Error};
use crate::{apis::ResponseContent, models};
use reqwest::StatusCode;
use serde::{de, Deserialize, Deserializer, Serialize};
#[derive(Clone, Debug)]
pub struct GetAllNpcItemsParams {
pub code: Option<String>,
pub npc: Option<String>,
pub currency: Option<String>,
pub page: Option<u32>,
pub size: Option<u32>,
}
impl GetAllNpcItemsParams {
pub fn new(
code: Option<String>,
npc: Option<String>,
currency: Option<String>,
page: Option<u32>,
size: Option<u32>,
) -> Self {
Self {
code,
npc,
currency,
page,
size,
}
}
}
#[derive(Clone, Debug)]
pub struct GetAllNpcsParams {
pub name: Option<String>,
pub r#type: Option<models::NpcType>,
pub page: Option<u32>,
pub size: Option<u32>,
}
impl GetAllNpcsParams {
pub fn new(
name: Option<String>,
r#type: Option<models::NpcType>,
page: Option<u32>,
size: Option<u32>,
) -> Self {
Self {
name,
r#type,
page,
size,
}
}
}
#[derive(Clone, Debug)]
pub struct GetNpcParams {
pub code: String,
}
impl GetNpcParams {
pub fn new(code: String) -> Self {
Self { code }
}
}
#[derive(Clone, Debug)]
pub struct GetNpcItemsParams {
pub code: String,
pub page: Option<u32>,
pub size: Option<u32>,
}
impl GetNpcItemsParams {
pub fn new(code: String, page: Option<u32>, size: Option<u32>) -> Self {
Self { code, page, size }
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum GetAllNpcItemsError {}
impl<'de> Deserialize<'de> for GetAllNpcItemsError {
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 GetAllNpcsError {}
impl<'de> Deserialize<'de> for GetAllNpcsError {
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 GetNpcError {
Status404(models::ErrorResponseSchema),
}
impl<'de> Deserialize<'de> for GetNpcError {
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 GetNpcItemsError {
Status404(models::ErrorResponseSchema),
}
impl<'de> Deserialize<'de> for GetNpcItemsError {
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_npc_items(
configuration: &configuration::Configuration,
params: GetAllNpcItemsParams,
) -> Result<models::DataPageNpcItem, Error<GetAllNpcItemsError>> {
let local_var_configuration = configuration;
let code = params.code;
let npc = params.npc;
let currency = params.currency;
let page = params.page;
let size = params.size;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/npcs/items", 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) = code {
local_var_req_builder =
local_var_req_builder.query(&[("code", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = npc {
local_var_req_builder = local_var_req_builder.query(&[("npc", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = currency {
local_var_req_builder =
local_var_req_builder.query(&[("currency", &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<GetAllNpcItemsError> =
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_all_npcs(
configuration: &configuration::Configuration,
params: GetAllNpcsParams,
) -> Result<models::DataPageNpcSchema, Error<GetAllNpcsError>> {
let local_var_configuration = configuration;
let name = params.name;
let r#type = params.r#type;
let page = params.page;
let size = params.size;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/npcs/details", 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) = name {
local_var_req_builder =
local_var_req_builder.query(&[("name", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = r#type {
local_var_req_builder =
local_var_req_builder.query(&[("type", &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<GetAllNpcsError> =
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_npc(
configuration: &configuration::Configuration,
params: GetNpcParams,
) -> Result<models::NpcResponseSchema, Error<GetNpcError>> {
let local_var_configuration = configuration;
let code = params.code;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/npcs/details/{code}",
local_var_configuration.base_path,
code = crate::apis::urlencode(code)
);
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<GetNpcError> = 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_npc_items(
configuration: &configuration::Configuration,
params: GetNpcItemsParams,
) -> Result<models::DataPageNpcItem, Error<GetNpcItemsError>> {
let local_var_configuration = configuration;
let code = params.code;
let page = params.page;
let size = params.size;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/npcs/items/{code}",
local_var_configuration.base_path,
code = crate::apis::urlencode(code)
);
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) = 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<GetNpcItemsError> =
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))
}
}