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 JobsApiRoutesBatchCancelBatchJobError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum JobsApiRoutesBatchCreateBatchJobError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum JobsApiRoutesBatchGetBatchJobError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum JobsApiRoutesBatchGetBatchJobsError {
UnknownValue(serde_json::Value),
}
pub async fn jobs_api_routes_batch_cancel_batch_job(configuration: &configuration::Configuration, job_id: &str) -> Result<models::BatchJobOut, Error<JobsApiRoutesBatchCancelBatchJobError>> {
let p_path_job_id = job_id;
let uri_str = format!("{}/v1/batch/jobs/{job_id}/cancel", configuration.base_path, job_id=crate::apis::urlencode(p_path_job_id));
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());
}
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 => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchJobOut`"))),
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::BatchJobOut`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<JobsApiRoutesBatchCancelBatchJobError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn jobs_api_routes_batch_create_batch_job(configuration: &configuration::Configuration, batch_job_in: models::BatchJobIn) -> Result<models::BatchJobOut, Error<JobsApiRoutesBatchCreateBatchJobError>> {
let p_body_batch_job_in = batch_job_in;
let uri_str = format!("{}/v1/batch/jobs", 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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_batch_job_in);
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::BatchJobOut`"))),
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::BatchJobOut`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<JobsApiRoutesBatchCreateBatchJobError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn jobs_api_routes_batch_get_batch_job(configuration: &configuration::Configuration, job_id: &str, inline: Option<bool>) -> Result<models::BatchJobOut, Error<JobsApiRoutesBatchGetBatchJobError>> {
let p_path_job_id = job_id;
let p_query_inline = inline;
let uri_str = format!("{}/v1/batch/jobs/{job_id}", configuration.base_path, job_id=crate::apis::urlencode(p_path_job_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_inline {
req_builder = req_builder.query(&[("inline", ¶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(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 => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchJobOut`"))),
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::BatchJobOut`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<JobsApiRoutesBatchGetBatchJobError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn jobs_api_routes_batch_get_batch_jobs(configuration: &configuration::Configuration, page: Option<i32>, page_size: Option<i32>, model: Option<&str>, agent_id: Option<&str>, metadata: Option<std::collections::HashMap<String, serde_json::Value>>, created_after: Option<String>, created_by_me: Option<bool>, status: Option<Vec<models::BatchJobStatus>>, order_by: Option<&str>) -> Result<models::BatchJobsOut, Error<JobsApiRoutesBatchGetBatchJobsError>> {
let p_query_page = page;
let p_query_page_size = page_size;
let p_query_model = model;
let p_query_agent_id = agent_id;
let p_query_metadata = metadata;
let p_query_created_after = created_after;
let p_query_created_by_me = created_by_me;
let p_query_status = status;
let p_query_order_by = order_by;
let uri_str = format!("{}/v1/batch/jobs", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
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_page_size {
req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_model {
req_builder = req_builder.query(&[("model", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_agent_id {
req_builder = req_builder.query(&[("agent_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_metadata {
req_builder = req_builder.query(&[("metadata", &serde_json::to_string(param_value)?)]);
}
if let Some(ref param_value) = p_query_created_after {
req_builder = req_builder.query(&[("created_after", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_created_by_me {
req_builder = req_builder.query(&[("created_by_me", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_status {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("status", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_query_order_by {
req_builder = req_builder.query(&[("order_by", ¶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(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 => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchJobsOut`"))),
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::BatchJobsOut`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<JobsApiRoutesBatchGetBatchJobsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}