use objc::{msg_send, sel, sel_impl};
use rust_macios_objective_c_runtime_proc_macros::interface_impl;
use crate::{
foundation::{NSArray, NSString},
object,
objective_c_runtime::{
nil,
traits::{FromId, PNSObject},
},
};
use super::un_notification_action::UNNotificationAction;
object! {
unsafe pub struct UNNotificationCategory;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u64)]
pub enum UNNotificationCategoryOptions {
None = 0,
CustomDismissAction = (1 << 0),
AllowInCarPlay = (1 << 1),
HiddenPreviewsShowTitle = (1 << 2),
HiddenPreviewsShowSubtitle = (1 << 3),
#[deprecated]
AllowAnnouncement = (1 << 4),
}
#[interface_impl(NSObject)]
impl UNNotificationCategory {
#[method]
pub fn category_with_identifier_actions_intent_identifiers_options(
identifier: NSString,
actions: NSArray<UNNotificationAction>,
intent_identifiers: NSArray<NSString>,
options: &[UNNotificationCategoryOptions],
) -> Self
where
Self: Sized + FromId,
{
let options = options
.iter()
.fold(0u64, |init, option| init | *option as u64);
unsafe {
Self::from_id(
msg_send![Self::m_class(), categoryWithIdentifier: identifier actions: actions intentIdentifiers: intent_identifiers options: options],
)
}
}
#[method]
pub fn category_with_identifier_actions_intent_identifiers_hidden_previews_body_placeholder_options(
identifier: NSString,
actions: NSArray<UNNotificationAction>,
intent_identifiers: NSArray<NSString>,
hidden_previews_body_placeholder: Option<NSString>,
options: &[UNNotificationCategoryOptions],
) -> Self
where
Self: Sized + FromId,
{
let hidden_previews_body_placeholder = match hidden_previews_body_placeholder {
Some(value) => value.m_self(),
None => nil,
};
let options = options
.iter()
.fold(0u64, |init, option| init | *option as u64);
unsafe {
Self::from_id(
msg_send![Self::m_class(), categoryWithIdentifier: identifier actions: actions intentIdentifiers: intent_identifiers hiddenPreviewsBodyPlaceholder: hidden_previews_body_placeholder options: options],
)
}
}
pub fn categoryWithIdentifier_actions_intentIdentifiers_hiddenPreviewsBodyPlaceholder_categorySummaryFormat_options(
identifier: NSString,
actions: NSArray<UNNotificationAction>,
intent_identifiers: NSArray<NSString>,
hidden_previews_body_placeholder: NSString,
category_summary_format: NSString,
options: &[UNNotificationCategoryOptions],
) -> Self
where
Self: Sized + FromId,
{
let options = options
.iter()
.fold(0u64, |init, option| init | *option as u64);
unsafe {
Self::from_id(
msg_send![Self::m_class(), categoryWithIdentifier: identifier actions: actions intentIdentifiers: intent_identifiers hiddenPreviewsBodyPlaceholder: hidden_previews_body_placeholder categorySummaryFormat: categorySummaryFormat options: options],
)
}
}
#[property]
pub fn identifier(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), identifier]) }
}
#[property]
pub fn actions(&self) -> NSArray<UNNotificationAction> {
unsafe { NSArray::from_id(msg_send![self.m_self(), actions]) }
}
#[property]
pub fn intent_identifiers(&self) -> NSArray<NSString> {
unsafe { NSArray::from_id(msg_send![self.m_self(), intentIdentifiers]) }
}
#[property]
pub fn hidden_previews_body_placeholder(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), hiddenPreviewsBodyPlaceholder]) }
}
#[property]
pub fn category_summary_format(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), categorySummaryFormat]) }
}
#[property]
pub fn options(&self) -> UNNotificationCategoryOptions {
unsafe { msg_send![self.m_self(), options] }
}
}