#![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 NotificationRules<'c> {
pub(crate) client: &'c AxiamClient,
pub(crate) scope: Scope,
}
impl std::fmt::Debug for NotificationRules<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("NotificationRules")
.field("scope", &self.scope)
.finish()
}
}
impl<'c> NotificationRules<'c> {
pub(crate) fn new(client: &'c AxiamClient) -> Self {
Self {
client,
scope: Scope::default(),
}
}
pub async fn list(
&self,
page: PageRequest,
) -> Result<Page<models::NotificationRuleResponse>, AxiamError> {
let query = page.query();
let call = Call {
operation: "notification_rules.list",
verb: Verb::Get,
path_template: "/api/v1/notification-rules",
path: "/api/v1/notification-rules".to_string(),
query: &query,
};
self.client
.management_send::<_, Page<models::NotificationRuleResponse>>(call, None::<&()>)
.await
}
pub async fn list_all(
&self,
start: PageRequest,
) -> Result<Vec<models::NotificationRuleResponse>, AxiamError> {
collect_pages(start, |p| self.list(p)).await
}
pub async fn create(
&self,
body: &models::CreateNotificationRuleRequest,
) -> Result<models::NotificationRuleResponse, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "notification_rules.create",
verb: Verb::Post,
path_template: "/api/v1/notification-rules",
path: "/api/v1/notification-rules".to_string(),
query: &query,
};
self.client
.management_send::<_, models::NotificationRuleResponse>(call, Some(body))
.await
}
pub async fn get(&self, id: Uuid) -> Result<models::NotificationRuleResponse, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "notification_rules.get",
verb: Verb::Get,
path_template: "/api/v1/notification-rules/{id}",
path: format!("/api/v1/notification-rules/{id}"),
query: &query,
};
self.client
.management_send::<_, models::NotificationRuleResponse>(call, None::<&()>)
.await
}
pub async fn update(
&self,
id: Uuid,
body: &models::UpdateNotificationRuleRequest,
) -> Result<models::NotificationRuleResponse, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "notification_rules.update",
verb: Verb::Put,
path_template: "/api/v1/notification-rules/{id}",
path: format!("/api/v1/notification-rules/{id}"),
query: &query,
};
self.client
.management_send::<_, models::NotificationRuleResponse>(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: "notification_rules.delete",
verb: Verb::Delete,
path_template: "/api/v1/notification-rules/{id}",
path: format!("/api/v1/notification-rules/{id}"),
query: &query,
};
self.client
.management_send_no_content(call, None::<&()>)
.await
}
}