use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Get1Error {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum MeError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Save1Error {
UnknownValue(serde_json::Value),
}
pub async fn get1(
configuration: &configuration::Configuration,
) -> Result<models::PersonalInfo, Error<Get1Error>> {
let uri_str = format!("{}/api/personal-info", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PersonalInfo`"))),
ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::PersonalInfo`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<Get1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn me(
configuration: &configuration::Configuration,
) -> Result<models::User, Error<MeError>> {
let uri_str = format!("{}/api/personal-info/@me", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::User`"))),
ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::User`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<MeError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn save1(
configuration: &configuration::Configuration,
ceo_full_name: &str,
note: &str,
organization_address: &str,
demo_mode: bool,
finance_charge: f64,
organization_city: &str,
organization_name: &str,
organization_bank_account: &str,
organization_bank_bic: &str,
organization_email_address: &str,
organization_post_code: &str,
country_code: &str,
max_days_to_pay: i32,
organization_phone_number: &str,
accountants: &str,
vat_number: &str,
signature: Option<std::path::PathBuf>,
logo: Option<std::path::PathBuf>,
initial: Option<std::path::PathBuf>,
) -> Result<models::PersonalInfo, Error<Save1Error>> {
let p_query_ceo_full_name = ceo_full_name;
let p_query_note = note;
let p_query_organization_address = organization_address;
let p_query_demo_mode = demo_mode;
let p_query_finance_charge = finance_charge;
let p_query_organization_city = organization_city;
let p_query_organization_name = organization_name;
let p_query_organization_bank_account = organization_bank_account;
let p_query_organization_bank_bic = organization_bank_bic;
let p_query_organization_email_address = organization_email_address;
let p_query_organization_post_code = organization_post_code;
let p_query_country_code = country_code;
let p_query_max_days_to_pay = max_days_to_pay;
let p_query_organization_phone_number = organization_phone_number;
let p_query_accountants = accountants;
let p_query_vat_number = vat_number;
let p_form_signature = signature;
let p_form_logo = logo;
let p_form_initial = initial;
let uri_str = format!("{}/api/personal-info/submit", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("ceoFullName", &p_query_ceo_full_name.to_string())]);
req_builder = req_builder.query(&[("note", &p_query_note.to_string())]);
req_builder = req_builder.query(&[(
"organizationAddress",
&p_query_organization_address.to_string(),
)]);
req_builder = req_builder.query(&[("demoMode", &p_query_demo_mode.to_string())]);
req_builder = req_builder.query(&[("financeCharge", &p_query_finance_charge.to_string())]);
req_builder =
req_builder.query(&[("organizationCity", &p_query_organization_city.to_string())]);
req_builder =
req_builder.query(&[("organizationName", &p_query_organization_name.to_string())]);
req_builder = req_builder.query(&[(
"organizationBankAccount",
&p_query_organization_bank_account.to_string(),
)]);
req_builder = req_builder.query(&[(
"organizationBankBIC",
&p_query_organization_bank_bic.to_string(),
)]);
req_builder = req_builder.query(&[(
"organizationEmailAddress",
&p_query_organization_email_address.to_string(),
)]);
req_builder = req_builder.query(&[(
"organizationPostCode",
&p_query_organization_post_code.to_string(),
)]);
req_builder = req_builder.query(&[("countryCode", &p_query_country_code.to_string())]);
req_builder = req_builder.query(&[("maxDaysToPay", &p_query_max_days_to_pay.to_string())]);
req_builder = req_builder.query(&[(
"organizationPhoneNumber",
&p_query_organization_phone_number.to_string(),
)]);
req_builder = req_builder.query(&[("accountants", &p_query_accountants.to_string())]);
req_builder = req_builder.query(&[("vatNumber", &p_query_vat_number.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let multipart_form = reqwest::multipart::Form::new();
req_builder = req_builder.multipart(multipart_form);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PersonalInfo`"))),
ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::PersonalInfo`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<Save1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}