use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ArchiveSupplySourceError {
Status400(models::supply_sources_2020_07_01::ErrorList),
Status403(models::supply_sources_2020_07_01::ErrorList),
Status404(models::supply_sources_2020_07_01::ErrorList),
Status413(models::supply_sources_2020_07_01::ErrorList),
Status415(models::supply_sources_2020_07_01::ErrorList),
Status429(models::supply_sources_2020_07_01::ErrorList),
Status500(models::supply_sources_2020_07_01::ErrorList),
Status503(models::supply_sources_2020_07_01::ErrorList),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateSupplySourceError {
Status400(models::supply_sources_2020_07_01::ErrorList),
Status403(models::supply_sources_2020_07_01::ErrorList),
Status404(models::supply_sources_2020_07_01::ErrorList),
Status413(models::supply_sources_2020_07_01::ErrorList),
Status415(models::supply_sources_2020_07_01::ErrorList),
Status429(models::supply_sources_2020_07_01::ErrorList),
Status500(models::supply_sources_2020_07_01::ErrorList),
Status503(models::supply_sources_2020_07_01::ErrorList),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSupplySourceError {
Status400(models::supply_sources_2020_07_01::ErrorList),
Status403(models::supply_sources_2020_07_01::ErrorList),
Status404(models::supply_sources_2020_07_01::ErrorList),
Status413(models::supply_sources_2020_07_01::ErrorList),
Status415(models::supply_sources_2020_07_01::ErrorList),
Status429(models::supply_sources_2020_07_01::ErrorList),
Status500(models::supply_sources_2020_07_01::ErrorList),
Status503(models::supply_sources_2020_07_01::ErrorList),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSupplySourcesError {
Status400(models::supply_sources_2020_07_01::ErrorList),
Status403(models::supply_sources_2020_07_01::ErrorList),
Status404(models::supply_sources_2020_07_01::ErrorList),
Status413(models::supply_sources_2020_07_01::ErrorList),
Status415(models::supply_sources_2020_07_01::ErrorList),
Status429(models::supply_sources_2020_07_01::ErrorList),
Status500(models::supply_sources_2020_07_01::ErrorList),
Status503(models::supply_sources_2020_07_01::ErrorList),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateSupplySourceError {
Status400(models::supply_sources_2020_07_01::ErrorList),
Status403(models::supply_sources_2020_07_01::ErrorList),
Status404(models::supply_sources_2020_07_01::ErrorList),
Status413(models::supply_sources_2020_07_01::ErrorList),
Status415(models::supply_sources_2020_07_01::ErrorList),
Status429(models::supply_sources_2020_07_01::ErrorList),
Status500(models::supply_sources_2020_07_01::ErrorList),
Status503(models::supply_sources_2020_07_01::ErrorList),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateSupplySourceStatusError {
Status400(models::supply_sources_2020_07_01::ErrorList),
Status403(models::supply_sources_2020_07_01::ErrorList),
Status404(models::supply_sources_2020_07_01::ErrorList),
Status413(models::supply_sources_2020_07_01::ErrorList),
Status415(models::supply_sources_2020_07_01::ErrorList),
Status429(models::supply_sources_2020_07_01::ErrorList),
Status500(models::supply_sources_2020_07_01::ErrorList),
Status503(models::supply_sources_2020_07_01::ErrorList),
UnknownValue(serde_json::Value),
}
pub async fn archive_supply_source(configuration: &configuration::Configuration, supply_source_id: &str) -> Result<models::supply_sources_2020_07_01::ErrorList, Error<ArchiveSupplySourceError>> {
let p_supply_source_id = supply_source_id;
let uri_str = format!("{}/supplySources/2020-07-01/supplySources/{supplySourceId}", configuration.base_path, supplySourceId=crate::apis::urlencode(p_supply_source_id));
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
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 => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::supply_sources_2020_07_01::ErrorList`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::supply_sources_2020_07_01::ErrorList`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ArchiveSupplySourceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn create_supply_source(configuration: &configuration::Configuration, payload: models::supply_sources_2020_07_01::CreateSupplySourceRequest) -> Result<models::supply_sources_2020_07_01::CreateSupplySourceResponse, Error<CreateSupplySourceError>> {
let p_payload = payload;
let uri_str = format!("{}/supplySources/2020-07-01/supplySources", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_payload);
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 => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::supply_sources_2020_07_01::CreateSupplySourceResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::supply_sources_2020_07_01::CreateSupplySourceResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateSupplySourceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_supply_source(configuration: &configuration::Configuration, supply_source_id: &str) -> Result<models::supply_sources_2020_07_01::SupplySource, Error<GetSupplySourceError>> {
let p_supply_source_id = supply_source_id;
let uri_str = format!("{}/supplySources/2020-07-01/supplySources/{supplySourceId}", configuration.base_path, supplySourceId=crate::apis::urlencode(p_supply_source_id));
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());
}
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 => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::supply_sources_2020_07_01::SupplySource`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::supply_sources_2020_07_01::SupplySource`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetSupplySourceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_supply_sources(configuration: &configuration::Configuration, next_page_token: Option<&str>, page_size: Option<f64>) -> Result<models::supply_sources_2020_07_01::GetSupplySourcesResponse, Error<GetSupplySourcesError>> {
let p_next_page_token = next_page_token;
let p_page_size = page_size;
let uri_str = format!("{}/supplySources/2020-07-01/supplySources", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_next_page_token {
req_builder = req_builder.query(&[("nextPageToken", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_page_size {
req_builder = req_builder.query(&[("pageSize", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
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 => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::supply_sources_2020_07_01::GetSupplySourcesResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::supply_sources_2020_07_01::GetSupplySourcesResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetSupplySourcesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn update_supply_source(configuration: &configuration::Configuration, supply_source_id: &str, payload: Option<models::supply_sources_2020_07_01::UpdateSupplySourceRequest>) -> Result<models::supply_sources_2020_07_01::ErrorList, Error<UpdateSupplySourceError>> {
let p_supply_source_id = supply_source_id;
let p_payload = payload;
let uri_str = format!("{}/supplySources/2020-07-01/supplySources/{supplySourceId}", configuration.base_path, supplySourceId=crate::apis::urlencode(p_supply_source_id));
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_payload);
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 => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::supply_sources_2020_07_01::ErrorList`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::supply_sources_2020_07_01::ErrorList`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UpdateSupplySourceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn update_supply_source_status(configuration: &configuration::Configuration, supply_source_id: &str, payload: Option<models::supply_sources_2020_07_01::UpdateSupplySourceStatusRequest>) -> Result<models::supply_sources_2020_07_01::ErrorList, Error<UpdateSupplySourceStatusError>> {
let p_supply_source_id = supply_source_id;
let p_payload = payload;
let uri_str = format!("{}/supplySources/2020-07-01/supplySources/{supplySourceId}/status", configuration.base_path, supplySourceId=crate::apis::urlencode(p_supply_source_id));
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_payload);
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 => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::supply_sources_2020_07_01::ErrorList`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::supply_sources_2020_07_01::ErrorList`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UpdateSupplySourceStatusError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}