use libc::c_double;
use objc::{msg_send, sel, sel_impl};
use rust_macios_objective_c_runtime_proc_macros::interface_impl;
use crate::{
foundation::{NSArray, NSDictionary, NSError, NSNumber, NSString, UInt},
object,
objective_c_runtime::{
id,
traits::{FromId, PNSObject},
},
utils::to_optional,
};
use super::{UNNotificationAttachment, UNNotificationSound};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[repr(i64)]
pub enum UNNotificationInterruptionLevel {
Passive,
Active,
TimeSensitive,
Critical,
}
object! {
unsafe pub struct UNNotificationContent;
}
#[interface_impl(NSObject)]
impl UNNotificationContent {
#[property]
pub fn title(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), title]) }
}
#[property]
pub fn subtitle(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), subtitle]) }
}
#[property]
pub fn body(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), body]) }
}
#[property]
pub fn attachments(&self) -> NSArray<UNNotificationAttachment> {
unsafe { NSArray::from_id(msg_send![self.m_self(), attachments]) }
}
#[property]
pub fn user_info(&self) -> NSDictionary<id, id> {
unsafe { NSDictionary::from_id(msg_send![self.m_self(), userInfo]) }
}
#[property]
pub fn launch_image_name(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), launchImageName]) }
}
#[property]
pub fn badge(&self) -> Option<NSNumber> {
unsafe { to_optional(msg_send![self.m_self(), badge]) }
}
#[property]
pub fn target_content_identifier(&self) -> Option<NSString> {
unsafe { to_optional(msg_send![self.m_self(), targetContentIdentifier]) }
}
#[property]
pub fn sound(&self) -> Option<UNNotificationSound> {
unsafe { to_optional(msg_send![self.m_self(), sound]) }
}
#[property]
pub fn interruption_level(&self) -> UNNotificationInterruptionLevel {
unsafe { msg_send![self.m_self(), interruptionLevel] }
}
#[property]
pub fn relevance_score(&self) -> c_double {
unsafe { msg_send![self.m_self(), relevanceScore] }
}
#[property]
pub fn filter_criteria(&self) -> Option<NSString> {
unsafe { to_optional(msg_send![self.m_self(), filterCriteria]) }
}
#[property]
pub fn thread_identifier(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), threadIdentifier]) }
}
#[property]
pub fn category_identifier(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), categoryIdentifier]) }
}
#[property]
pub fn summary_argument(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), summaryArgument]) }
}
#[property]
pub fn summary_argument_count(&self) -> UInt {
unsafe { msg_send![self.m_self(), summaryArgumentCount] }
}
#[method]
pub fn content_by_updating_with_provider(
&mut self,
provider: id,
) -> Result<UNNotificationContent, NSError> {
unsafe {
let mut error = NSError::m_alloc();
let ptr = UNNotificationContent::from_id(
msg_send![self.m_self(), contentByUpdatingWithProvider: provider error: &mut error],
);
if error.m_self().is_null() {
Ok(ptr)
} else {
Err(error)
}
}
}
}