use std::sync::Arc;
use crate::error::{map_manager_err, ManagerError};
use crate::gen::manager::apis::configuration::Configuration;
use crate::gen::manager::apis::events_api as api;
use crate::gen::manager::models;
use crate::retry::{with_retry, RetryPolicy};
pub struct EventsResource {
pub(crate) cfg: Arc<Configuration>,
pub(crate) retry: RetryPolicy,
}
impl EventsResource {
pub async fn list(&self) -> Result<Vec<models::Event>, ManagerError> {
let resp = with_retry(&self.retry, true, || {
api::list_events(self.cfg.as_ref(), None)
})
.await
.map_err(map_manager_err)?;
Ok(resp.items)
}
pub async fn create_custom(
&self,
body: models::CustomEventRequest,
) -> Result<models::EventItemResponse, ManagerError> {
with_retry(&self.retry, false, || {
api::create_custom_event(self.cfg.as_ref(), body.clone())
})
.await
.map_err(map_manager_err)
}
pub async fn delete_custom(&self, id: &str) -> Result<(), ManagerError> {
with_retry(&self.retry, false, || {
api::delete_custom_event(self.cfg.as_ref(), id)
})
.await
.map_err(map_manager_err)
}
}