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 GetTripsCollectionIdError {
Status400(models::Problem),
Status401(models::Problem),
Status403(models::Problem),
Status404(models::Problem),
Status406(models::Problem),
Status415(models::Problem),
Status500(models::Problem),
Status501(models::Problem),
Status503(models::Problem),
DefaultResponse(models::Problem),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetTripsIdError {
Status400(models::Problem),
Status401(models::Problem),
Status403(models::Problem),
Status404(models::Problem),
Status406(models::Problem),
Status415(models::Problem),
Status500(models::Problem),
Status501(models::Problem),
Status503(models::Problem),
DefaultResponse(models::Problem),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PostTripsError {
Status400(models::Problem),
Status401(models::Problem),
Status403(models::Problem),
Status404(models::Problem),
Status406(models::Problem),
Status415(models::Problem),
Status500(models::Problem),
Status501(models::Problem),
Status503(models::Problem),
DefaultResponse(models::Problem),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PostTripsChangeError {
Status400(models::Problem),
Status401(models::Problem),
Status403(models::Problem),
Status404(models::Problem),
Status406(models::Problem),
Status415(models::Problem),
Status500(models::Problem),
Status501(models::Problem),
Status503(models::Problem),
DefaultResponse(models::Problem),
UnknownValue(serde_json::Value),
}
pub async fn get_trips_collection_id(configuration: &configuration::Configuration, trips_collection_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>, stop_behavior: Option<models::StopBehavior>, page: Option<&str>, embed: Option<Vec<models::TripsCollectionResponseContent>>) -> Result<models::TripCollectionResponse, Error<GetTripsCollectionIdError>> {
let p_path_trips_collection_id = trips_collection_id;
let p_header_requestor = requestor;
let p_header_accept_language = accept_language;
let p_header_traceparent = traceparent;
let p_header_tracestate = tracestate;
let p_header_x_accept_namespace = x_accept_namespace;
let p_query_stop_behavior = stop_behavior;
let p_query_page = page;
let p_query_embed = embed;
let uri_str = format!("{}/trips-collections/{tripsCollectionId}", configuration.base_path, tripsCollectionId=crate::apis::urlencode(p_path_trips_collection_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_stop_behavior {
req_builder = req_builder.query(&[("stopBehavior", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_page {
req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_embed {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("embed".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("embed", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").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(param_value) = p_header_requestor {
req_builder = req_builder.header("Requestor", param_value.to_string());
}
if let Some(param_value) = p_header_accept_language {
req_builder = req_builder.header("Accept-Language", param_value.to_string());
}
if let Some(param_value) = p_header_traceparent {
req_builder = req_builder.header("traceparent", param_value.to_string());
}
if let Some(param_value) = p_header_tracestate {
req_builder = req_builder.header("tracestate", param_value.to_string());
}
if let Some(param_value) = p_header_x_accept_namespace {
req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
}
if let Some(ref token) = configuration.oauth_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 => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TripCollectionResponse`"))),
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::TripCollectionResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetTripsCollectionIdError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_trips_id(configuration: &configuration::Configuration, trip_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>, stop_behavior: Option<models::StopBehavior>, embed: Option<Vec<models::TripResponseContent>>) -> Result<models::TripResponse, Error<GetTripsIdError>> {
let p_path_trip_id = trip_id;
let p_header_requestor = requestor;
let p_header_accept_language = accept_language;
let p_header_traceparent = traceparent;
let p_header_tracestate = tracestate;
let p_header_x_accept_namespace = x_accept_namespace;
let p_query_stop_behavior = stop_behavior;
let p_query_embed = embed;
let uri_str = format!("{}/trips/{tripId}", configuration.base_path, tripId=crate::apis::urlencode(p_path_trip_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_stop_behavior {
req_builder = req_builder.query(&[("stopBehavior", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_embed {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("embed".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("embed", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").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(param_value) = p_header_requestor {
req_builder = req_builder.header("Requestor", param_value.to_string());
}
if let Some(param_value) = p_header_accept_language {
req_builder = req_builder.header("Accept-Language", param_value.to_string());
}
if let Some(param_value) = p_header_traceparent {
req_builder = req_builder.header("traceparent", param_value.to_string());
}
if let Some(param_value) = p_header_tracestate {
req_builder = req_builder.header("tracestate", param_value.to_string());
}
if let Some(param_value) = p_header_x_accept_namespace {
req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
}
if let Some(ref token) = configuration.oauth_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 => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TripResponse`"))),
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::TripResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetTripsIdError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn post_trips(configuration: &configuration::Configuration, trip_search_criteria: models::TripSearchCriteria, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>, stop_behavior: Option<models::StopBehavior>) -> Result<models::TripCollectionResponse, Error<PostTripsError>> {
let p_body_trip_search_criteria = trip_search_criteria;
let p_header_requestor = requestor;
let p_header_accept_language = accept_language;
let p_header_traceparent = traceparent;
let p_header_tracestate = tracestate;
let p_header_x_accept_namespace = x_accept_namespace;
let p_query_stop_behavior = stop_behavior;
let uri_str = format!("{}/trips-collection", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_query_stop_behavior {
req_builder = req_builder.query(&[("stopBehavior", ¶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());
}
if let Some(param_value) = p_header_requestor {
req_builder = req_builder.header("Requestor", param_value.to_string());
}
if let Some(param_value) = p_header_accept_language {
req_builder = req_builder.header("Accept-Language", param_value.to_string());
}
if let Some(param_value) = p_header_traceparent {
req_builder = req_builder.header("traceparent", param_value.to_string());
}
if let Some(param_value) = p_header_tracestate {
req_builder = req_builder.header("tracestate", param_value.to_string());
}
if let Some(param_value) = p_header_x_accept_namespace {
req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_trip_search_criteria);
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::TripCollectionResponse`"))),
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::TripCollectionResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PostTripsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn post_trips_change(configuration: &configuration::Configuration, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, stop_behavior: Option<models::StopBehavior>, trip_change_criteria: Option<models::TripChangeCriteria>) -> Result<models::TripResponse, Error<PostTripsChangeError>> {
let p_header_requestor = requestor;
let p_header_accept_language = accept_language;
let p_header_traceparent = traceparent;
let p_header_tracestate = tracestate;
let p_query_stop_behavior = stop_behavior;
let p_body_trip_change_criteria = trip_change_criteria;
let uri_str = format!("{}/trips", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_query_stop_behavior {
req_builder = req_builder.query(&[("stopBehavior", ¶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());
}
if let Some(param_value) = p_header_requestor {
req_builder = req_builder.header("Requestor", param_value.to_string());
}
if let Some(param_value) = p_header_accept_language {
req_builder = req_builder.header("Accept-Language", param_value.to_string());
}
if let Some(param_value) = p_header_traceparent {
req_builder = req_builder.header("traceparent", param_value.to_string());
}
if let Some(param_value) = p_header_tracestate {
req_builder = req_builder.header("tracestate", param_value.to_string());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_trip_change_criteria);
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::TripResponse`"))),
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::TripResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PostTripsChangeError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}