use super::{configuration, Error};
use crate::{apis::ResponseContent, models};
use reqwest::StatusCode;
use serde::{de, Deserialize, Deserializer, Serialize};
#[derive(Clone, Debug)]
pub struct CreateAccountParams {
pub add_account_schema: models::AddAccountSchema,
}
impl CreateAccountParams {
pub fn new(add_account_schema: models::AddAccountSchema) -> Self {
Self { add_account_schema }
}
}
#[derive(Clone, Debug)]
pub struct ForgotPasswordParams {
pub password_reset_request_schema: models::PasswordResetRequestSchema,
}
impl ForgotPasswordParams {
pub fn new(password_reset_request_schema: models::PasswordResetRequestSchema) -> Self {
Self {
password_reset_request_schema,
}
}
}
#[derive(Clone, Debug)]
pub struct GetAccountParams {
pub account: String,
}
impl GetAccountParams {
pub fn new(account: String) -> Self {
Self { account }
}
}
#[derive(Clone, Debug)]
pub struct GetAccountAchievementsParams {
pub account: String,
pub r#type: Option<String>,
pub completed: Option<bool>,
pub page: Option<u32>,
pub size: Option<u32>,
}
impl GetAccountAchievementsParams {
pub fn new(
account: String,
r#type: Option<String>,
completed: Option<bool>,
page: Option<u32>,
size: Option<u32>,
) -> Self {
Self {
account,
r#type,
completed,
page,
size,
}
}
}
#[derive(Clone, Debug)]
pub struct GetAccountCharactersParams {
pub account: String,
}
impl GetAccountCharactersParams {
pub fn new(account: String) -> Self {
Self { account }
}
}
#[derive(Clone, Debug)]
pub struct ResetPasswordParams {
pub password_reset_confirm_schema: models::PasswordResetConfirmSchema,
}
impl ResetPasswordParams {
pub fn new(password_reset_confirm_schema: models::PasswordResetConfirmSchema) -> Self {
Self {
password_reset_confirm_schema,
}
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum CreateAccountError {
Status456(models::ErrorResponseSchema),
Status457(models::ErrorResponseSchema),
Status422(models::ErrorResponseSchema),
}
impl<'de> Deserialize<'de> for CreateAccountError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
match raw.error.code {
456 => Ok(Self::Status456(raw)),
457 => Ok(Self::Status457(raw)),
422 => Ok(Self::Status422(raw)),
_ => Err(de::Error::custom(format!(
"Unexpected error code: {}",
raw.error.code
))),
}
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum ForgotPasswordError {
Status422(models::ErrorResponseSchema),
}
impl<'de> Deserialize<'de> for ForgotPasswordError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
match raw.error.code {
422 => Ok(Self::Status422(raw)),
_ => Err(de::Error::custom(format!(
"Unexpected error code: {}",
raw.error.code
))),
}
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum GetAccountError {
Status404(models::ErrorResponseSchema),
}
impl<'de> Deserialize<'de> for GetAccountError {
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 GetAccountAchievementsError {
Status404(models::ErrorResponseSchema),
}
impl<'de> Deserialize<'de> for GetAccountAchievementsError {
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 GetAccountCharactersError {}
impl<'de> Deserialize<'de> for GetAccountCharactersError {
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 ResetPasswordError {
Status561(models::ErrorResponseSchema),
Status562(models::ErrorResponseSchema),
Status560(models::ErrorResponseSchema),
Status422(models::ErrorResponseSchema),
}
impl<'de> Deserialize<'de> for ResetPasswordError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
match raw.error.code {
561 => Ok(Self::Status561(raw)),
562 => Ok(Self::Status562(raw)),
560 => Ok(Self::Status560(raw)),
422 => Ok(Self::Status422(raw)),
_ => Err(de::Error::custom(format!(
"Unexpected error code: {}",
raw.error.code
))),
}
}
}
pub async fn create_account(
configuration: &configuration::Configuration,
params: CreateAccountParams,
) -> Result<models::ResponseSchema, Error<CreateAccountError>> {
let local_var_configuration = configuration;
let add_account_schema = params.add_account_schema;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/accounts/create", local_var_configuration.base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, 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());
}
local_var_req_builder = local_var_req_builder.json(&add_account_schema);
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<CreateAccountError> =
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 forgot_password(
configuration: &configuration::Configuration,
params: ForgotPasswordParams,
) -> Result<models::PasswordResetResponseSchema, Error<ForgotPasswordError>> {
let local_var_configuration = configuration;
let password_reset_request_schema = params.password_reset_request_schema;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/accounts/forgot_password",
local_var_configuration.base_path
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, 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());
}
local_var_req_builder = local_var_req_builder.json(&password_reset_request_schema);
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<ForgotPasswordError> =
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_account(
configuration: &configuration::Configuration,
params: GetAccountParams,
) -> Result<models::AccountDetailsSchema, Error<GetAccountError>> {
let local_var_configuration = configuration;
let account = params.account;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/accounts/{account}",
local_var_configuration.base_path,
account = crate::apis::urlencode(account)
);
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<GetAccountError> =
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_account_achievements(
configuration: &configuration::Configuration,
params: GetAccountAchievementsParams,
) -> Result<models::DataPageAccountAchievementSchema, Error<GetAccountAchievementsError>> {
let local_var_configuration = configuration;
let account = params.account;
let r#type = params.r#type;
let completed = params.completed;
let page = params.page;
let size = params.size;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/accounts/{account}/achievements",
local_var_configuration.base_path,
account = crate::apis::urlencode(account)
);
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) = r#type {
local_var_req_builder =
local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = completed {
local_var_req_builder =
local_var_req_builder.query(&[("completed", &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<GetAccountAchievementsError> =
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_account_characters(
configuration: &configuration::Configuration,
params: GetAccountCharactersParams,
) -> Result<models::CharactersListSchema, Error<GetAccountCharactersError>> {
let local_var_configuration = configuration;
let account = params.account;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/accounts/{account}/characters",
local_var_configuration.base_path,
account = crate::apis::urlencode(account)
);
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<GetAccountCharactersError> =
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 reset_password(
configuration: &configuration::Configuration,
params: ResetPasswordParams,
) -> Result<models::PasswordResetResponseSchema, Error<ResetPasswordError>> {
let local_var_configuration = configuration;
let password_reset_confirm_schema = params.password_reset_confirm_schema;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/accounts/reset_password",
local_var_configuration.base_path
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, 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());
}
local_var_req_builder = local_var_req_builder.json(&password_reset_confirm_schema);
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<ResetPasswordError> =
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))
}
}