use objc::{msg_send, sel, sel_impl};
use rust_macios_objective_c_runtime_proc_macros::interface_impl;
use crate::{
foundation::NSString,
object,
objective_c_runtime::traits::{FromId, PNSObject},
utils::to_optional,
};
use super::UNNotificationActionIcon;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u64)]
pub enum UNNotificationActionOptions {
None = 0,
AuthenticationRequired = (1 << 0),
Destructive = (1 << 1),
Foreground = (1 << 2),
}
object! {
unsafe pub struct UNNotificationAction;
}
#[interface_impl(NSObject)]
impl UNNotificationAction {
#[method]
pub fn action_with_identifier_title_options(
identifier: NSString,
title: NSString,
options: &[UNNotificationActionOptions],
) -> Self
where
Self: Sized + FromId,
{
let options = options.iter().fold(0, |init, option| init | *option as u64);
unsafe {
Self::from_id(
msg_send![Self::m_class(), actionWithIdentifier: identifier title: title options: options],
)
}
}
#[method]
pub fn action_with_identifier_title_options_icon(
identifier: NSString,
title: NSString,
options: &[UNNotificationActionOptions],
icon: UNNotificationActionIcon,
) -> Self
where
Self: Sized + FromId,
{
let options = options.iter().fold(0, |init, option| init | *option as u64);
unsafe {
Self::from_id(
msg_send![Self::m_class(), actionWithIdentifier: identifier title: title options: options icon: icon],
)
}
}
#[property]
pub fn identifier(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), identifier]) }
}
#[property]
pub fn title(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), title]) }
}
#[property]
pub fn icon(&self) -> Option<UNNotificationActionIcon> {
unsafe { to_optional(msg_send![self.m_self(), icon]) }
}
#[property]
pub fn options(&self) -> UNNotificationActionOptions {
unsafe { msg_send![self.m_self(), options] }
}
}