use objc::{msg_send, sel, sel_impl};
use crate::{
foundation::NSString,
object,
objective_c_runtime::{
macros::interface_impl,
nil,
traits::{FromId, PNSObject},
},
utils::to_bool,
};
use super::{CNMutableContact, CNMutableGroup, ICNContact, ICNGroup};
object! {
unsafe pub struct CNSaveRequest;
}
#[interface_impl(NSObject)]
impl CNSaveRequest {
#[method]
pub fn add_contact_to_container_with_identifier<Contact>(
&self,
contact: Contact,
identifier: Option<NSString>,
) where
Contact: ICNContact,
{
match identifier {
Some(identifier) => unsafe {
msg_send![self.m_self(), addContact: contact.m_self() toContainerWithIdentifier: identifier]
},
None => unsafe {
msg_send![self.m_self(), addContact: contact.m_self() toContainerWithIdentifier: nil]
},
}
}
#[method]
pub fn update_contact(&self, contact: CNMutableContact) {
unsafe { msg_send![self.m_self(), updateContact: contact] }
}
#[method]
pub fn delete_contact(&self, contact: CNMutableContact) {
unsafe { msg_send![self.m_self(), deleteContact: contact] }
}
#[method]
pub fn add_group_to_container_with_identifier(
&self,
group: CNMutableGroup,
identifier: NSString,
) {
unsafe { msg_send![self.m_self(), addGroup: group toContainerWithIdentifier: identifier] }
}
#[method]
pub fn update_group(&self, group: CNMutableGroup) {
unsafe { msg_send![self.m_self(), updateGroup: group] }
}
#[method]
pub fn delete_group(&self, group: CNMutableGroup) {
unsafe { msg_send![self.m_self(), deleteGroup: group] }
}
#[method]
pub fn add_member_to_group<Contact, Group>(&self, contact: Contact, group: Group)
where
Contact: ICNContact,
Group: ICNGroup,
{
unsafe { msg_send![self.m_self(), addMember: contact toGroup: group] }
}
#[method]
pub fn remove_member_from_group<Contact, Group>(&self, contact: Contact, group: Group)
where
Contact: ICNContact,
Group: ICNGroup,
{
unsafe { msg_send![self.m_self(), removeMember: contact fromGroup: group] }
}
#[method]
pub fn add_subgroup_to_group<Group, ParentGroup>(&self, group: Group, parent_group: ParentGroup)
where
Group: ICNGroup,
ParentGroup: ICNGroup,
{
unsafe { msg_send![self.m_self(), addSubgroup: group toGroup: parent_group] }
}
#[method]
pub fn remove_subgroup_from_group<Group, ParentGroup>(
&self,
group: Group,
parent_group: ParentGroup,
) where
Group: ICNGroup,
ParentGroup: ICNGroup,
{
unsafe { msg_send![self.m_self(), removeSubgroup: group fromGroup: parent_group] }
}
#[property]
pub fn should_refetch_contacts(&self) -> bool {
unsafe { to_bool(msg_send![self.m_self(), shouldRefetchContacts]) }
}
#[property]
pub fn transaction_author(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), transactionAuthor]) }
}
}