Skip to main content

ferro_notifications/
channel.rs

1//! Notification channel abstraction.
2
3use serde::{Deserialize, Serialize};
4
5/// Available notification channels.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
7#[serde(rename_all = "lowercase")]
8pub enum Channel {
9    /// Email notifications via SMTP.
10    Mail,
11    /// Database notifications for in-app delivery.
12    Database,
13    /// Slack webhook notifications.
14    Slack,
15    /// SMS notifications (future).
16    Sms,
17    /// Push notifications (future).
18    Push,
19}
20
21impl Channel {
22    /// Get channel name as string.
23    pub fn as_str(&self) -> &'static str {
24        match self {
25            Channel::Mail => "mail",
26            Channel::Database => "database",
27            Channel::Slack => "slack",
28            Channel::Sms => "sms",
29            Channel::Push => "push",
30        }
31    }
32}
33
34impl std::fmt::Display for Channel {
35    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        write!(f, "{}", self.as_str())
37    }
38}
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn test_channel_as_str() {
46        assert_eq!(Channel::Mail.as_str(), "mail");
47        assert_eq!(Channel::Database.as_str(), "database");
48        assert_eq!(Channel::Slack.as_str(), "slack");
49    }
50
51    #[test]
52    fn test_channel_display() {
53        assert_eq!(format!("{}", Channel::Mail), "mail");
54    }
55}