use bon::bon;
use reqwest;
use std::sync::Arc;
use serde::{Deserialize, Serialize, de::Error as OtherError};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};
use crate::apis::ContentType;
use crate::*;
#[async_trait]
pub trait TasksApi: Send + Sync {
async fn list(&self, params: ListParams) -> Result<crate::tasks::TaskListResponseBase, Error>;
async fn get(&self, params: GetParams) -> Result<crate::tasks::GetResponse, Error>;
async fn cancel(&self, params: CancelParams) -> Result<crate::tasks::TaskListResponseBase, Error>;
}
pub struct TasksApiClient {
configuration: Arc<crate::Configuration>
}
impl TasksApiClient {
pub fn new(configuration: Arc<crate::Configuration>) -> Self {
Self { configuration }
}
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct ListParams {
pub timeout: Option<String>,
pub actions: Option<common::Actions>,
pub detailed: Option<bool>,
pub error_trace: Option<bool>,
pub filter_path: Option<common::FilterPath>,
pub group_by: Option<String>,
pub human: Option<bool>,
pub nodes: Option<Vec<String>>,
pub parent_task_id: Option<String>,
pub pretty: Option<bool>,
pub source: Option<String>,
pub wait_for_completion: Option<bool>,
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct GetParams {
pub timeout: Option<String>,
pub error_trace: Option<bool>,
pub filter_path: Option<common::FilterPath>,
pub human: Option<bool>,
pub pretty: Option<bool>,
pub source: Option<String>,
pub task_id: String,
pub wait_for_completion: Option<bool>,
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct CancelParams {
pub actions: Option<common::Actions>,
pub error_trace: Option<bool>,
pub filter_path: Option<common::FilterPath>,
pub human: Option<bool>,
pub nodes: Option<Vec<String>>,
pub parent_task_id: Option<String>,
pub pretty: Option<bool>,
pub source: Option<String>,
pub task_id: String,
pub wait_for_completion: Option<bool>,
}
#[async_trait]
impl TasksApi for TasksApiClient {
async fn list(&self, params: ListParams) -> Result<crate::tasks::TaskListResponseBase, Error> {
let ListParams {
timeout,
actions,
detailed,
error_trace,
filter_path,
group_by,
human,
nodes,
parent_task_id,
pretty,
source,
wait_for_completion,
} = params;
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}_tasks", local_var_configuration.base_path);
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) = nodes {
local_var_req_builder = match "multi" {
"multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("nodes".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => local_var_req_builder.query(&[("nodes", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref local_var_str) = timeout {
local_var_req_builder = local_var_req_builder.query(&[("timeout", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = filter_path {
local_var_req_builder = local_var_req_builder.query(&[("filter_path", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = actions {
local_var_req_builder = local_var_req_builder.query(&[("actions", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = parent_task_id {
local_var_req_builder = local_var_req_builder.query(&[("parent_task_id", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = pretty {
local_var_req_builder = local_var_req_builder.query(&[("pretty", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = detailed {
local_var_req_builder = local_var_req_builder.query(&[("detailed", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = wait_for_completion {
local_var_req_builder = local_var_req_builder.query(&[("wait_for_completion", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = source {
local_var_req_builder = local_var_req_builder.query(&[("source", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = group_by {
local_var_req_builder = local_var_req_builder.query(&[("group_by", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = error_trace {
local_var_req_builder = local_var_req_builder.query(&[("error_trace", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = human {
local_var_req_builder = local_var_req_builder.query(&[("human", &local_var_str.to_string())]);
}
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_error = ResponseContent {
status: local_var_status,
content: local_var_content,
};
Err(Error::ApiError(local_var_error))
}
} async fn get(&self, params: GetParams) -> Result<crate::tasks::GetResponse, Error> {
let GetParams {
timeout,
error_trace,
filter_path,
human,
pretty,
source,
task_id,
wait_for_completion,
} = params;
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}_tasks/{task_id}", local_var_configuration.base_path, task_id=task_id);
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) = pretty {
local_var_req_builder = local_var_req_builder.query(&[("pretty", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = human {
local_var_req_builder = local_var_req_builder.query(&[("human", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = filter_path {
local_var_req_builder = local_var_req_builder.query(&[("filter_path", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = wait_for_completion {
local_var_req_builder = local_var_req_builder.query(&[("wait_for_completion", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = error_trace {
local_var_req_builder = local_var_req_builder.query(&[("error_trace", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = timeout {
local_var_req_builder = local_var_req_builder.query(&[("timeout", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = source {
local_var_req_builder = local_var_req_builder.query(&[("source", &local_var_str.to_string())]);
}
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_error = ResponseContent {
status: local_var_status,
content: local_var_content,
};
Err(Error::ApiError(local_var_error))
}
} async fn cancel(&self, params: CancelParams) -> Result<crate::tasks::TaskListResponseBase, Error> {
let CancelParams {
actions,
error_trace,
filter_path,
human,
nodes,
parent_task_id,
pretty,
source,
task_id,
wait_for_completion,
} = params;
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}_tasks/{task_id}/_cancel", local_var_configuration.base_path, task_id=task_id);
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_str) = source {
local_var_req_builder = local_var_req_builder.query(&[("source", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = filter_path {
local_var_req_builder = local_var_req_builder.query(&[("filter_path", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = actions {
local_var_req_builder = local_var_req_builder.query(&[("actions", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = pretty {
local_var_req_builder = local_var_req_builder.query(&[("pretty", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = human {
local_var_req_builder = local_var_req_builder.query(&[("human", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = error_trace {
local_var_req_builder = local_var_req_builder.query(&[("error_trace", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = parent_task_id {
local_var_req_builder = local_var_req_builder.query(&[("parent_task_id", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = nodes {
local_var_req_builder = match "multi" {
"multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("nodes".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => local_var_req_builder.query(&[("nodes", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref local_var_str) = wait_for_completion {
local_var_req_builder = local_var_req_builder.query(&[("wait_for_completion", &local_var_str.to_string())]);
}
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_error = ResponseContent {
status: local_var_status,
content: local_var_content,
};
Err(Error::ApiError(local_var_error))
}
}
}