Skip to main content

brevo_rust/api/types/
notification.rs

1pub use crate::prelude::*;
2
3/// Optional. Use this object if you want to let Brevo send an email to the contact, with the payment request URL. If empty, no notifications (message and reminders) will be sent.
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
5pub struct Notification {
6    /// Channel used to send the notifications.
7    pub channel: String,
8    /// Use this field if you want to give more context to your contact about the payment request.
9    #[serde(default)]
10    pub text: String,
11}
12
13impl Notification {
14    pub fn builder() -> NotificationBuilder {
15        <NotificationBuilder as Default>::default()
16    }
17}
18
19#[derive(Clone, PartialEq, Default, Debug)]
20#[non_exhaustive]
21pub struct NotificationBuilder {
22    channel: Option<String>,
23    text: Option<String>,
24}
25
26impl NotificationBuilder {
27    pub fn channel(mut self, value: impl Into<String>) -> Self {
28        self.channel = Some(value.into());
29        self
30    }
31
32    pub fn text(mut self, value: impl Into<String>) -> Self {
33        self.text = Some(value.into());
34        self
35    }
36
37    /// Consumes the builder and constructs a [`Notification`].
38    /// This method will fail if any of the following fields are not set:
39    /// - [`channel`](NotificationBuilder::channel)
40    /// - [`text`](NotificationBuilder::text)
41    pub fn build(self) -> Result<Notification, BuildError> {
42        Ok(Notification {
43            channel: self
44                .channel
45                .ok_or_else(|| BuildError::missing_field("channel"))?,
46            text: self.text.ok_or_else(|| BuildError::missing_field("text"))?,
47        })
48    }
49}