use crate::error::Error;
use crate::http::HttpClient;
use crate::types::admin::{ClearTenantResponse, FactoryResetResponse, ListTenantsResponse};
use crate::types::common::RequestOptions;
#[derive(Debug, Clone)]
pub struct AdminClient {
http: HttpClient,
}
impl AdminClient {
pub(crate) fn new(http: HttpClient) -> Self {
Self { http }
}
pub async fn clear_all_data(
&self,
options: Option<&RequestOptions>,
) -> Result<FactoryResetResponse, Error> {
self.http
.post("/admin/clear-all", &serde_json::json!({}), options)
.await
}
pub async fn clear_tenant_data(
&self,
tenant_id: &str,
options: Option<&RequestOptions>,
) -> Result<ClearTenantResponse, Error> {
let path = format!("/admin/clear-tenant/{}", encode(tenant_id));
self.http.post(&path, &serde_json::json!({}), options).await
}
pub async fn list_tenants(
&self,
options: Option<&RequestOptions>,
) -> Result<ListTenantsResponse, Error> {
self.http.get("/admin/tenants", None, options).await
}
}
fn encode(s: &str) -> String {
url::form_urlencoded::byte_serialize(s.as_bytes()).collect()
}