use std::sync::Arc;
use crate::error::{map_manager_err, ManagerError};
use crate::gen::manager::apis::configuration::Configuration;
use crate::gen::manager::apis::manager_api as api;
use crate::gen::manager::models;
use crate::retry::{with_retry, RetryPolicy};
pub struct SystemResource {
pub(crate) cfg: Arc<Configuration>,
pub(crate) retry: RetryPolicy,
}
impl SystemResource {
pub async fn echo(&self) -> Result<models::GenericItemResponse, ManagerError> {
with_retry(&self.retry, true, || api::echo(self.cfg.as_ref()))
.await
.map_err(map_manager_err)
}
pub async fn ping(&self) -> Result<models::GenericItemResponse, ManagerError> {
with_retry(&self.retry, true, || api::ping(self.cfg.as_ref()))
.await
.map_err(map_manager_err)
}
pub async fn api_status(&self) -> Result<models::GenericItemResponse, ManagerError> {
with_retry(&self.retry, true, || api::get_api_status(self.cfg.as_ref()))
.await
.map_err(map_manager_err)
}
pub async fn server_time(&self) -> Result<models::GenericItemResponse, ManagerError> {
with_retry(&self.retry, true, || {
api::get_server_time(self.cfg.as_ref())
})
.await
.map_err(map_manager_err)
}
pub async fn timezones(
&self,
q: Option<&str>,
max: Option<i32>,
) -> Result<models::ObjectListResponse, ManagerError> {
with_retry(&self.retry, true, || {
api::list_timezones(self.cfg.as_ref(), q, max)
})
.await
.map_err(map_manager_err)
}
pub async fn push_token(&self) -> Result<models::GenericItemResponse, ManagerError> {
with_retry(&self.retry, true, || api::get_push_token(self.cfg.as_ref()))
.await
.map_err(map_manager_err)
}
pub async fn tags(&self) -> Result<models::ObjectListResponse, ManagerError> {
with_retry(&self.retry, true, || api::list_tags(self.cfg.as_ref()))
.await
.map_err(map_manager_err)
}
pub async fn tags_by_category(
&self,
category: &str,
) -> Result<models::ObjectListResponse, ManagerError> {
with_retry(&self.retry, true, || {
api::list_tags_by_category(self.cfg.as_ref(), category)
})
.await
.map_err(map_manager_err)
}
pub async fn export_templates(
&self,
r#type: &str,
) -> Result<std::collections::HashMap<String, serde_json::Value>, ManagerError> {
with_retry(&self.retry, true, || {
api::export_templates(self.cfg.as_ref(), r#type)
})
.await
.map_err(map_manager_err)
}
}