use std::future::Future;
use serde::{Deserialize, Serialize};
use crate::error::Result;
use crate::response::BodyResponseProcessor;
use crate::{Client, Ops, Request};
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct CreateBatchBody {
pub project_name: String,
pub input: String,
pub actions: serde_json::Value,
#[serde(skip_serializing_if = "Option::is_none")]
pub notification: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<serde_json::Value>,
pub service_role: String,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct CreateBatchResponse {
#[serde(default)]
pub request_id: String,
#[serde(default)]
pub id: Option<String>,
}
pub struct CreateBatch {
pub body: CreateBatchBody,
}
impl Ops for CreateBatch {
const ACTION: &'static str = "CreateBatch";
type Query = ();
type Body = CreateBatchBody;
type Response = BodyResponseProcessor<CreateBatchResponse>;
fn into_parts(self) -> (Self::Query, Self::Body) {
((), self.body)
}
}
pub trait CreateBatchOps {
fn create_batch(&self, body: CreateBatchBody) -> impl Future<Output = Result<CreateBatchResponse>>;
}
impl CreateBatchOps for Client {
async fn create_batch(&self, body: CreateBatchBody) -> Result<CreateBatchResponse> {
self.request(CreateBatch { body }).await
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetBatchQuery {
pub project_name: String,
pub id: String,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetBatchResponse {
#[serde(default)]
pub request_id: String,
#[serde(default)]
pub batch: Option<String>,
}
pub struct GetBatch {
pub query: GetBatchQuery,
}
impl Ops for GetBatch {
const ACTION: &'static str = "GetBatch";
type Query = GetBatchQuery;
type Body = ();
type Response = BodyResponseProcessor<GetBatchResponse>;
fn into_parts(self) -> (Self::Query, Self::Body) {
(self.query, ())
}
}
pub trait GetBatchOps {
fn get_batch(&self, query: GetBatchQuery) -> impl Future<Output = Result<GetBatchResponse>>;
}
impl GetBatchOps for Client {
async fn get_batch(&self, query: GetBatchQuery) -> Result<GetBatchResponse> {
self.request(GetBatch { query }).await
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ListBatchesQuery {
pub project_name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub state: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sort: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub order: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tag_selector: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_results: Option<i32>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ListBatchesResponse {
#[serde(default)]
pub request_id: String,
#[serde(default)]
pub batches: Vec<serde_json::Value>,
#[serde(default)]
pub next_token: Option<String>,
}
pub struct ListBatches {
pub query: ListBatchesQuery,
}
impl Ops for ListBatches {
const ACTION: &'static str = "ListBatches";
type Query = ListBatchesQuery;
type Body = ();
type Response = BodyResponseProcessor<ListBatchesResponse>;
fn into_parts(self) -> (Self::Query, Self::Body) {
(self.query, ())
}
}
pub trait ListBatchesOps {
fn list_batches(&self, query: ListBatchesQuery) -> impl Future<Output = Result<ListBatchesResponse>>;
}
impl ListBatchesOps for Client {
async fn list_batches(&self, query: ListBatchesQuery) -> Result<ListBatchesResponse> {
self.request(ListBatches { query }).await
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct UpdateBatchBody {
pub project_name: String,
pub id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub input: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub actions: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<serde_json::Value>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct UpdateBatchResponse {
#[serde(default)]
pub request_id: String,
}
pub struct UpdateBatch {
pub body: UpdateBatchBody,
}
impl Ops for UpdateBatch {
const ACTION: &'static str = "UpdateBatch";
type Query = ();
type Body = UpdateBatchBody;
type Response = BodyResponseProcessor<UpdateBatchResponse>;
fn into_parts(self) -> (Self::Query, Self::Body) {
((), self.body)
}
}
pub trait UpdateBatchOps {
fn update_batch(&self, body: UpdateBatchBody) -> impl Future<Output = Result<UpdateBatchResponse>>;
}
impl UpdateBatchOps for Client {
async fn update_batch(&self, body: UpdateBatchBody) -> Result<UpdateBatchResponse> {
self.request(UpdateBatch { body }).await
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct DeleteBatchBody {
pub project_name: String,
pub id: String,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct DeleteBatchResponse {
#[serde(default)]
pub request_id: String,
}
pub struct DeleteBatch {
pub body: DeleteBatchBody,
}
impl Ops for DeleteBatch {
const ACTION: &'static str = "DeleteBatch";
type Query = ();
type Body = DeleteBatchBody;
type Response = BodyResponseProcessor<DeleteBatchResponse>;
fn into_parts(self) -> (Self::Query, Self::Body) {
((), self.body)
}
}
pub trait DeleteBatchOps {
fn delete_batch(&self, body: DeleteBatchBody) -> impl Future<Output = Result<DeleteBatchResponse>>;
}
impl DeleteBatchOps for Client {
async fn delete_batch(&self, body: DeleteBatchBody) -> Result<DeleteBatchResponse> {
self.request(DeleteBatch { body }).await
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct SuspendBatchBody {
pub project_name: String,
pub id: String,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct SuspendBatchResponse {
#[serde(default)]
pub request_id: String,
}
pub struct SuspendBatch {
pub body: SuspendBatchBody,
}
impl Ops for SuspendBatch {
const ACTION: &'static str = "SuspendBatch";
type Query = ();
type Body = SuspendBatchBody;
type Response = BodyResponseProcessor<SuspendBatchResponse>;
fn into_parts(self) -> (Self::Query, Self::Body) {
((), self.body)
}
}
pub trait SuspendBatchOps {
fn suspend_batch(&self, body: SuspendBatchBody) -> impl Future<Output = Result<SuspendBatchResponse>>;
}
impl SuspendBatchOps for Client {
async fn suspend_batch(&self, body: SuspendBatchBody) -> Result<SuspendBatchResponse> {
self.request(SuspendBatch { body }).await
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ResumeBatchBody {
pub project_name: String,
pub id: String,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ResumeBatchResponse {
#[serde(default)]
pub request_id: String,
}
pub struct ResumeBatch {
pub body: ResumeBatchBody,
}
impl Ops for ResumeBatch {
const ACTION: &'static str = "ResumeBatch";
type Query = ();
type Body = ResumeBatchBody;
type Response = BodyResponseProcessor<ResumeBatchResponse>;
fn into_parts(self) -> (Self::Query, Self::Body) {
((), self.body)
}
}
pub trait ResumeBatchOps {
fn resume_batch(&self, body: ResumeBatchBody) -> impl Future<Output = Result<ResumeBatchResponse>>;
}
impl ResumeBatchOps for Client {
async fn resume_batch(&self, body: ResumeBatchBody) -> Result<ResumeBatchResponse> {
self.request(ResumeBatch { body }).await
}
}
pub trait BatchOperations:
CreateBatchOps
+ GetBatchOps
+ ListBatchesOps
+ UpdateBatchOps
+ DeleteBatchOps
+ SuspendBatchOps
+ ResumeBatchOps
{
}
impl<T> BatchOperations for T where
T: CreateBatchOps
+ GetBatchOps
+ ListBatchesOps
+ UpdateBatchOps
+ DeleteBatchOps
+ SuspendBatchOps
+ ResumeBatchOps
{
}