#![allow(clippy::doc_markdown, clippy::default_trait_access)]
#[allow(unused_imports, clippy::wildcard_imports)]
use crate::{error::Result, models::*, Configuration};
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct BatchJobsListOptions {
pub job_type: Option<BatchJobType>,
pub status: Option<Vec<BatchJobStatus>>,
pub page: Option<i32>,
pub per_page: Option<i32>,
}
impl BatchJobsListOptions {
#[must_use]
pub fn new() -> Self {
Self {
job_type: None,
status: None,
page: None,
per_page: None,
}
}
#[must_use]
pub fn job_type(mut self, job_type: impl Into<BatchJobType>) -> Self {
self.job_type = Some(job_type.into());
self
}
#[must_use]
pub fn maybe_job_type(mut self, job_type: Option<BatchJobType>) -> Self {
self.job_type = job_type;
self
}
#[must_use]
pub fn status(mut self, status: impl Into<Vec<BatchJobStatus>>) -> Self {
self.status = Some(status.into());
self
}
#[must_use]
pub fn maybe_status(mut self, status: Option<Vec<BatchJobStatus>>) -> Self {
self.status = status;
self
}
#[must_use]
pub fn page(mut self, page: impl Into<i32>) -> Self {
self.page = Some(page.into());
self
}
#[must_use]
pub fn maybe_page(mut self, page: Option<i32>) -> Self {
self.page = page;
self
}
#[must_use]
pub fn per_page(mut self, per_page: impl Into<i32>) -> Self {
self.per_page = Some(per_page.into());
self
}
#[must_use]
pub fn maybe_per_page(mut self, per_page: Option<i32>) -> Self {
self.per_page = per_page;
self
}
}
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct BatchJobsListFailuresOptions {
pub chunk_id: Option<BatchJobChunkId>,
pub limit: Option<i32>,
pub offset: Option<i32>,
}
impl BatchJobsListFailuresOptions {
#[must_use]
pub fn new() -> Self {
Self {
chunk_id: None,
limit: None,
offset: None,
}
}
#[must_use]
pub fn chunk_id(mut self, chunk_id: impl Into<BatchJobChunkId>) -> Self {
self.chunk_id = Some(chunk_id.into());
self
}
#[must_use]
pub fn maybe_chunk_id(mut self, chunk_id: Option<BatchJobChunkId>) -> Self {
self.chunk_id = chunk_id;
self
}
#[must_use]
pub fn limit(mut self, limit: impl Into<i32>) -> Self {
self.limit = Some(limit.into());
self
}
#[must_use]
pub fn maybe_limit(mut self, limit: Option<i32>) -> Self {
self.limit = limit;
self
}
#[must_use]
pub fn offset(mut self, offset: impl Into<i32>) -> Self {
self.offset = Some(offset.into());
self
}
#[must_use]
pub fn maybe_offset(mut self, offset: Option<i32>) -> Self {
self.offset = offset;
self
}
}
#[derive(Clone)]
pub struct BatchJobs {
cfg: std::sync::Arc<Configuration>,
options: crate::api::RequestOptions,
}
impl std::fmt::Debug for BatchJobs {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("BatchJobs")
.field("options", &self.options)
.finish_non_exhaustive()
}
}
impl BatchJobs {
pub(super) fn new(cfg: std::sync::Arc<Configuration>) -> Self {
Self {
cfg,
options: crate::api::RequestOptions::default(),
}
}
#[must_use]
pub fn with_options(mut self, options: crate::api::RequestOptions) -> Self {
self.options = options;
self
}
fn list_request(
&self,
options: impl Into<Option<BatchJobsListOptions>>,
) -> crate::api::Call<crate::models::BatchJobListResponse> {
let BatchJobsListOptions {
job_type,
status,
page,
per_page,
} = options.into().unwrap_or_default();
crate::request::Request::new(http::Method::GET, "/api/v1/batch-jobs")
.with_optional_query_param("job_type", job_type)
.with_optional_exploded_query_param("status", status)
.with_optional_query_param("page", page)
.with_optional_query_param("per_page", per_page)
.with_options(&self.options)
.json(&self.cfg)
}
pub fn list(
&self,
options: impl Into<Option<BatchJobsListOptions>>,
) -> crate::api::PageCall<crate::models::BatchJobListResponse, crate::models::BatchJobResponse>
{
static WALK: crate::api::pagination::Walk<BatchJobsListOptions> =
crate::api::pagination::Walk::Page {
first: 0,
get: |options| options.page.map(i64::from),
set: |options, position| options.page = i32::try_from(position).ok(),
};
let this = self.clone();
let call = move |options: BatchJobsListOptions| this.list_request(options);
crate::api::PageCall::new(
options.into().unwrap_or_default(),
WALK,
crate::api::pages::BATCH_JOBS_LIST,
call,
)
}
pub fn retrieve(
&self,
batch_job_id: impl Into<crate::models::BatchJobId>,
) -> crate::api::Call<crate::models::BatchJobDetailResponse> {
crate::request::Request::new(http::Method::GET, "/api/v1/batch-jobs/{batch_job_id}")
.with_path_param(
"batch_job_id",
Into::<crate::models::BatchJobId>::into(batch_job_id),
)
.with_options(&self.options)
.json(&self.cfg)
}
fn list_failures_request(
&self,
batch_job_id: impl Into<crate::models::BatchJobId>,
options: impl Into<Option<BatchJobsListFailuresOptions>>,
) -> crate::api::Call<crate::models::BatchJobFailuresResponse> {
let BatchJobsListFailuresOptions {
chunk_id,
limit,
offset,
} = options.into().unwrap_or_default();
crate::request::Request::new(
http::Method::GET,
"/api/v1/batch-jobs/{batch_job_id}/failures",
)
.with_path_param(
"batch_job_id",
Into::<crate::models::BatchJobId>::into(batch_job_id),
)
.with_optional_query_param("chunk_id", chunk_id)
.with_optional_query_param("limit", limit)
.with_optional_query_param("offset", offset)
.with_options(&self.options)
.json(&self.cfg)
}
pub fn list_failures(
&self,
batch_job_id: impl Into<crate::models::BatchJobId>,
options: impl Into<Option<BatchJobsListFailuresOptions>>,
) -> crate::api::PageCall<
crate::models::BatchJobFailuresResponse,
crate::models::BatchJobItemFailureResponse,
> {
static WALK: crate::api::pagination::Walk<BatchJobsListFailuresOptions> =
crate::api::pagination::Walk::Offset {
get: |options| options.offset.map(i64::from),
set: |options, position| options.offset = i32::try_from(position).ok(),
};
let batch_job_id: crate::models::BatchJobId = batch_job_id.into();
let this = self.clone();
let call = move |options: BatchJobsListFailuresOptions| {
this.list_failures_request(&batch_job_id, options)
};
crate::api::PageCall::new(
options.into().unwrap_or_default(),
WALK,
crate::api::pages::BATCH_JOBS_LIST_FAILURES,
call,
)
}
}