//! Contacts abstraction.
//!
//! `DbusContacts` is the provider — a D-Bus client of `contacts-server`
//! (the sibling Liberux daemon).

use crate::types::{ ContactRef, PhoneNumber };

pub mod dbus;

pub use dbus::DbusContacts;

#[ derive( Clone, Debug ) ]
pub enum ContactsError
{
	Backend( String ),
}

pub trait ContactsProvider
{
	fn search( &self, query: &str ) -> Result<Vec<ContactRef>, ContactsError>;
	fn lookup_by_number( &self, number: &PhoneNumber ) -> Result<Option<ContactRef>, ContactsError>;
	fn all( &self ) -> Result<Vec<ContactRef>, ContactsError>;

	/// Create a contact with a display name and a single Mobile phone number.
	/// Asynchronous: the new contact surfaces via [`Self::poll_changed`] once
	/// the server confirms the write.
	fn add_contact( &self, name: &str, number: &str ) -> Result<(), ContactsError>;

	/// Returns `true` once when the contact set has changed since the last
	/// call, so the UI can refresh its cached list from `all()`. Polled from
	/// the app tick. Static providers never change, hence the default.
	fn poll_changed( &self ) -> bool
	{
		false
	}
}
