#![allow(clippy::too_many_arguments)]
use uuid::Uuid;
use crate::AxiamError;
use crate::client::AxiamClient;
use crate::management::models;
use crate::management::page::{Page, PageRequest, collect_pages};
use crate::management::request::{Call, Verb};
use crate::management::scope::Scope;
#[derive(Clone, Copy)]
pub struct Reactors<'c> {
pub(crate) client: &'c AxiamClient,
pub(crate) scope: Scope,
}
impl std::fmt::Debug for Reactors<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Reactors")
.field("scope", &self.scope)
.finish()
}
}
impl<'c> Reactors<'c> {
pub(crate) fn new(client: &'c AxiamClient) -> Self {
Self {
client,
scope: Scope::default(),
}
}
pub async fn list(
&self,
page: PageRequest,
) -> Result<Page<models::ReactorResponse>, AxiamError> {
let query = page.query();
let call = Call {
operation: "reactors.list",
verb: Verb::Get,
path_template: "/api/v1/reactors",
path: "/api/v1/reactors".to_string(),
query: &query,
};
self.client
.management_send::<_, Page<models::ReactorResponse>>(call, None::<&()>)
.await
}
pub async fn list_all(
&self,
start: PageRequest,
) -> Result<Vec<models::ReactorResponse>, AxiamError> {
collect_pages(start, |p| self.list(p)).await
}
pub async fn create(
&self,
body: &models::CreateReactorRequest,
) -> Result<models::ReactorResponse, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "reactors.create",
verb: Verb::Post,
path_template: "/api/v1/reactors",
path: "/api/v1/reactors".to_string(),
query: &query,
};
self.client
.management_send::<_, models::ReactorResponse>(call, Some(body))
.await
}
pub async fn get(&self, id: Uuid) -> Result<models::ReactorResponse, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "reactors.get",
verb: Verb::Get,
path_template: "/api/v1/reactors/{id}",
path: format!("/api/v1/reactors/{id}"),
query: &query,
};
self.client
.management_send::<_, models::ReactorResponse>(call, None::<&()>)
.await
}
pub async fn update(
&self,
id: Uuid,
body: &models::UpdateReactorRequest,
) -> Result<models::ReactorResponse, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "reactors.update",
verb: Verb::Put,
path_template: "/api/v1/reactors/{id}",
path: format!("/api/v1/reactors/{id}"),
query: &query,
};
self.client
.management_send::<_, models::ReactorResponse>(call, Some(body))
.await
}
pub async fn delete(&self, id: Uuid) -> Result<(), AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "reactors.delete",
verb: Verb::Delete,
path_template: "/api/v1/reactors/{id}",
path: format!("/api/v1/reactors/{id}"),
query: &query,
};
self.client
.management_send_no_content(call, None::<&()>)
.await
}
pub async fn list_events(&self) -> Result<Vec<models::ReactorEventDescriptor>, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "reactors.list_events",
verb: Verb::Get,
path_template: "/api/v1/reactors/events",
path: "/api/v1/reactors/events".to_string(),
query: &query,
};
self.client
.management_send::<_, Vec<models::ReactorEventDescriptor>>(call, None::<&()>)
.await
}
}