#![allow(clippy::too_many_arguments)]
use uuid::Uuid;
use crate::AxiamError;
use crate::client::AxiamClient;
use crate::management::models;
use crate::management::request::{Call, Verb};
use crate::management::scope::Scope;
#[derive(Clone, Copy)]
pub struct EmailConfig<'c> {
pub(crate) client: &'c AxiamClient,
pub(crate) scope: Scope,
}
impl std::fmt::Debug for EmailConfig<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EmailConfig")
.field("scope", &self.scope)
.finish()
}
}
impl<'c> EmailConfig<'c> {
pub(crate) fn new(client: &'c AxiamClient) -> Self {
Self {
client,
scope: Scope::default(),
}
}
#[must_use]
pub fn in_org(mut self, org_id: Uuid) -> Self {
self.scope.org_id = Some(org_id);
self
}
#[must_use]
pub fn for_tenant(mut self, tenant_id: Uuid) -> Self {
self.scope.tenant_id = Some(tenant_id);
self
}
pub async fn get_org(&self) -> Result<models::EmailConfig, AxiamError> {
let org_id = self.scope.org(self.client, "email_config.get_org")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "email_config.get_org",
verb: Verb::Get,
path_template: "/api/v1/organizations/{org_id}/email-config",
path: format!("/api/v1/organizations/{org_id}/email-config"),
query: &query,
};
self.client
.management_send::<_, models::EmailConfig>(call, None::<&()>)
.await
}
pub async fn set_org(
&self,
body: &models::SetOrgEmailConfig,
) -> Result<models::EmailConfig, AxiamError> {
let org_id = self.scope.org(self.client, "email_config.set_org")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "email_config.set_org",
verb: Verb::Put,
path_template: "/api/v1/organizations/{org_id}/email-config",
path: format!("/api/v1/organizations/{org_id}/email-config"),
query: &query,
};
self.client
.management_send::<_, models::EmailConfig>(call, Some(body))
.await
}
pub async fn delete_org(&self) -> Result<(), AxiamError> {
let org_id = self.scope.org(self.client, "email_config.delete_org")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "email_config.delete_org",
verb: Verb::Delete,
path_template: "/api/v1/organizations/{org_id}/email-config",
path: format!("/api/v1/organizations/{org_id}/email-config"),
query: &query,
};
self.client
.management_send_no_content(call, None::<&()>)
.await
}
pub async fn test_org(&self) -> Result<models::EmailTestResult, AxiamError> {
let org_id = self.scope.org(self.client, "email_config.test_org")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "email_config.test_org",
verb: Verb::Post,
path_template: "/api/v1/organizations/{org_id}/email-config/test",
path: format!("/api/v1/organizations/{org_id}/email-config/test"),
query: &query,
};
self.client
.management_send::<_, models::EmailTestResult>(call, None::<&()>)
.await
}
pub async fn get_tenant(&self) -> Result<models::EmailConfigOverride, AxiamError> {
let tenant_id = self.scope.tenant(self.client, "email_config.get_tenant")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "email_config.get_tenant",
verb: Verb::Get,
path_template: "/api/v1/tenants/{tenant_id}/email-config",
path: format!("/api/v1/tenants/{tenant_id}/email-config"),
query: &query,
};
self.client
.management_send::<_, models::EmailConfigOverride>(call, None::<&()>)
.await
}
pub async fn set_tenant(
&self,
body: &models::EmailConfigOverride,
) -> Result<models::EmailConfigOverride, AxiamError> {
let tenant_id = self.scope.tenant(self.client, "email_config.set_tenant")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "email_config.set_tenant",
verb: Verb::Put,
path_template: "/api/v1/tenants/{tenant_id}/email-config",
path: format!("/api/v1/tenants/{tenant_id}/email-config"),
query: &query,
};
self.client
.management_send::<_, models::EmailConfigOverride>(call, Some(body))
.await
}
pub async fn delete_tenant(&self) -> Result<(), AxiamError> {
let tenant_id = self
.scope
.tenant(self.client, "email_config.delete_tenant")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "email_config.delete_tenant",
verb: Verb::Delete,
path_template: "/api/v1/tenants/{tenant_id}/email-config",
path: format!("/api/v1/tenants/{tenant_id}/email-config"),
query: &query,
};
self.client
.management_send_no_content(call, None::<&()>)
.await
}
pub async fn test_tenant(&self) -> Result<models::EmailTestResult, AxiamError> {
let tenant_id = self.scope.tenant(self.client, "email_config.test_tenant")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "email_config.test_tenant",
verb: Verb::Post,
path_template: "/api/v1/tenants/{tenant_id}/email-config/test",
path: format!("/api/v1/tenants/{tenant_id}/email-config/test"),
query: &query,
};
self.client
.management_send::<_, models::EmailTestResult>(call, None::<&()>)
.await
}
}