use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::{client::Sendry, error::Error};
#[derive(Debug, Clone)]
pub struct NotificationPreferencesResource {
client: Sendry,
}
impl NotificationPreferencesResource {
pub(crate) fn new(client: Sendry) -> Self {
Self { client }
}
pub async fn get(&self) -> Result<NotificationPreferences, Error> {
self.client
.request(self.client.build::<()>(
Method::GET,
"/v1/notification-preferences",
&[],
None,
))
.await
}
pub async fn update(
&self,
params: UpdateNotificationPreferences,
) -> Result<NotificationPreferences, Error> {
self.client
.request(self.client.build(
Method::PUT,
"/v1/notification-preferences",
&[],
Some(¶ms),
))
.await
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct NotificationPreferences {
pub id: String,
pub bounce_alerts: bool,
pub complaint_alerts: bool,
pub delivery_failures: bool,
pub domain_issues: bool,
pub daily_summary: bool,
pub weekly_digest: bool,
pub monthly_report: bool,
pub all_events: bool,
pub delivery_events: bool,
pub engagement_events: bool,
pub compliance_events: bool,
pub created_at: String,
pub updated_at: String,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct UpdateNotificationPreferences {
#[serde(rename = "bounceAlerts", skip_serializing_if = "Option::is_none")]
pub bounce_alerts: Option<bool>,
#[serde(rename = "complaintAlerts", skip_serializing_if = "Option::is_none")]
pub complaint_alerts: Option<bool>,
#[serde(rename = "deliveryFailures", skip_serializing_if = "Option::is_none")]
pub delivery_failures: Option<bool>,
#[serde(rename = "domainIssues", skip_serializing_if = "Option::is_none")]
pub domain_issues: Option<bool>,
#[serde(rename = "dailySummary", skip_serializing_if = "Option::is_none")]
pub daily_summary: Option<bool>,
#[serde(rename = "weeklyDigest", skip_serializing_if = "Option::is_none")]
pub weekly_digest: Option<bool>,
#[serde(rename = "monthlyReport", skip_serializing_if = "Option::is_none")]
pub monthly_report: Option<bool>,
#[serde(rename = "allEvents", skip_serializing_if = "Option::is_none")]
pub all_events: Option<bool>,
#[serde(rename = "deliveryEvents", skip_serializing_if = "Option::is_none")]
pub delivery_events: Option<bool>,
#[serde(rename = "engagementEvents", skip_serializing_if = "Option::is_none")]
pub engagement_events: Option<bool>,
#[serde(rename = "complianceEvents", skip_serializing_if = "Option::is_none")]
pub compliance_events: Option<bool>,
}