use crate::{Level, Notification};
#[derive(Debug, Default, Clone)]
pub struct NotificationBuilder {
device_key: Option<String>,
title: Option<String>,
body: Option<String>,
sound: Option<String>,
badge: Option<i32>,
icon: Option<String>,
group: Option<String>,
url: Option<String>,
copy: Option<String>,
action: Option<String>,
is_archive: Option<i32>,
is_url_encode: Option<i32>,
auto_copy: Option<i32>,
level: Option<Level>,
volume: Option<i32>,
call: Option<i32>,
}
impl NotificationBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn device_key(mut self, key: impl Into<String>) -> Self {
self.device_key = Some(key.into());
self
}
pub fn title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}
pub fn body(mut self, body: impl Into<String>) -> Self {
self.body = Some(body.into());
self
}
pub fn sound(mut self, sound: impl Into<String>) -> Self {
self.sound = Some(sound.into());
self
}
pub fn badge(mut self, badge: i32) -> Self {
self.badge = Some(badge);
self
}
pub fn icon(mut self, icon: impl Into<String>) -> Self {
self.icon = Some(icon.into());
self
}
pub fn group(mut self, group: impl Into<String>) -> Self {
self.group = Some(group.into());
self
}
pub fn url(mut self, url: impl Into<String>) -> Self {
self.url = Some(url.into());
self
}
pub fn copy(mut self, copy: impl Into<String>) -> Self {
self.copy = Some(copy.into());
self
}
pub fn action(mut self, action: impl Into<String>) -> Self {
self.action = Some(action.into());
self
}
pub fn archive(mut self, archive: bool) -> Self {
self.is_archive = Some(if archive { 1 } else { 0 });
self
}
pub fn url_encode(mut self, encode: bool) -> Self {
self.is_url_encode = Some(if encode { 1 } else { 0 });
self
}
pub fn auto_copy(mut self, auto_copy: bool) -> Self {
self.auto_copy = Some(if auto_copy { 1 } else { 0 });
self
}
pub fn level(mut self, level: Level) -> Self {
self.level = Some(level);
self
}
pub fn volume(mut self, volume: i32) -> Self {
self.volume = Some(volume);
self
}
pub fn call(mut self, call: bool) -> Self {
self.call = Some(if call { 1 } else { 0 });
self
}
pub fn build(self) -> Notification {
Notification {
device_key: self.device_key,
title: self.title,
body: self.body,
sound: self.sound,
badge: self.badge,
icon: self.icon,
group: self.group,
url: self.url,
copy: self.copy,
action: self.action,
is_archive: self.is_archive,
is_url_encode: self.is_url_encode,
auto_copy: self.auto_copy,
level: self.level,
volume: self.volume,
call: self.call,
}
}
}