serenade_notifier/
notification.rs1use crate::Channel;
4
5#[derive(Clone, Debug, Eq, PartialEq)]
7pub struct SmsMessage {
8 to: String,
9 body: String,
10}
11
12impl SmsMessage {
13 #[must_use]
15 pub fn new(to: impl Into<String>, body: impl Into<String>) -> Self {
16 Self {
17 to: to.into(),
18 body: body.into(),
19 }
20 }
21
22 #[must_use]
24 pub fn to(&self) -> &str {
25 &self.to
26 }
27
28 #[must_use]
30 pub fn body(&self) -> &str {
31 &self.body
32 }
33}
34
35#[derive(Clone, Debug, Eq, PartialEq)]
37pub struct PushMessage {
38 device_token: String,
39 title: String,
40 body: String,
41}
42
43impl PushMessage {
44 #[must_use]
46 pub fn new(
47 device_token: impl Into<String>,
48 title: impl Into<String>,
49 body: impl Into<String>,
50 ) -> Self {
51 Self {
52 device_token: device_token.into(),
53 title: title.into(),
54 body: body.into(),
55 }
56 }
57
58 #[must_use]
60 pub fn device_token(&self) -> &str {
61 &self.device_token
62 }
63
64 #[must_use]
66 pub fn title(&self) -> &str {
67 &self.title
68 }
69
70 #[must_use]
72 pub fn body(&self) -> &str {
73 &self.body
74 }
75}
76
77#[derive(Clone, Debug, Eq, PartialEq)]
79pub enum Notification {
80 Sms(SmsMessage),
82 Push(PushMessage),
84}
85
86impl Notification {
87 #[must_use]
89 pub const fn channel(&self) -> Channel {
90 match self {
91 Self::Sms(_) => Channel::Sms,
92 Self::Push(_) => Channel::Push,
93 }
94 }
95
96 #[must_use]
98 pub fn sms(to: impl Into<String>, body: impl Into<String>) -> Self {
99 Self::Sms(SmsMessage::new(to, body))
100 }
101
102 #[must_use]
104 pub fn push(
105 device_token: impl Into<String>,
106 title: impl Into<String>,
107 body: impl Into<String>,
108 ) -> Self {
109 Self::Push(PushMessage::new(device_token, title, body))
110 }
111}