use builder_pattern::Builder;
use serde::{Serialize, Deserialize};
use serde_with::skip_serializing_none;
#[skip_serializing_none]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Builder)]
pub struct Notification {
#[into]
#[default(None)]
pub badge: Option<String>,
#[into]
#[default(None)]
pub body: Option<String>,
#[into]
#[default(None)]
pub body_loc_args: Option<Vec<String>>,
#[into]
#[default(None)]
pub body_loc_key: Option<String>,
#[into]
#[default(None)]
pub click_action: Option<String>,
#[into]
#[default(None)]
pub color: Option<String>,
#[into]
#[default(None)]
pub icon: Option<String>,
#[into]
#[default(None)]
pub sound: Option<String>,
#[into]
#[default(None)]
pub tag: Option<String>,
#[into]
#[default(None)]
pub title: Option<String>,
#[into]
#[default(None)]
pub title_loc_args: Option<Vec<String>>,
#[into]
#[default(None)]
pub title_loc_key: Option<String>,
}
impl From<crate::client::notification::Notification> for Notification{
fn from(notification: crate::client::notification::Notification) -> Self {
Self {
badge: notification.badge,
body: notification.body,
body_loc_args: notification.body_loc_args,
body_loc_key: notification.body_loc_key,
click_action: Some(notification.click_action),
color: notification.color,
icon: notification.icon,
sound: notification.sound,
tag: notification.tag,
title: Some(notification.title),
title_loc_args: notification.title_loc_args,
title_loc_key: notification.title_loc_key,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_notification() {
let notification = Notification::new()
.badge("badge".to_string())
.body("body".to_string())
.body_loc_args(vec!["body_loc_args".to_string()])
.body_loc_key("body_loc_key".to_string())
.click_action("click_action".to_string())
.color("color".to_string())
.icon("icon".to_string())
.sound("sound".to_string())
.tag("tag".to_string())
.title("title".to_string())
.title_loc_args(vec!["title_loc_args".to_string()])
.title_loc_key("title_loc_key".to_string())
.build();
let expected = Notification {
badge: Some("badge".to_string()),
body: Some("body".to_string()),
body_loc_args: Some(vec!["body_loc_args".to_string()]),
body_loc_key: Some("body_loc_key".to_string()),
click_action: Some("click_action".to_string()),
color: Some("color".to_string()),
icon: Some("icon".to_string()),
sound: Some("sound".to_string()),
tag: Some("tag".to_string()),
title: Some("title".to_string()),
title_loc_args: Some(vec!["title_loc_args".to_string()]),
title_loc_key: Some("title_loc_key".to_string()),
};
assert_eq!(notification, expected);
}
}