use crate::error::CoreError;
use crate::ids::{ETag, ResourcePath};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ContactQuery {
pub text: String,
pub limit: u32,
pub include_groups: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct GroupRef {
pub path: ResourcePath,
pub name: String,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LabeledValue {
pub value: String,
pub label: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ContactList {
pub contacts: Vec<Contact>,
pub warnings: u32,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Contact {
pub path: ResourcePath,
pub etag: ETag,
pub full_name: String,
pub emails: Vec<LabeledValue>,
pub phones: Vec<LabeledValue>,
pub organization: Option<String>,
pub note: Option<String>,
pub is_group: bool,
pub groups: Vec<GroupRef>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ContactDraft {
pub full_name: String,
pub emails: Vec<String>,
pub phones: Vec<String>,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct ContactUpdate {
pub full_name: Option<String>,
pub emails: Option<Vec<String>>,
pub phones: Option<Vec<String>>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum GroupChange {
Add,
Remove,
}
#[trait_variant::make(Send)]
pub trait ContactsProvider {
async fn search(&self, query: &ContactQuery) -> Result<ContactList, CoreError>;
async fn get(&self, path: &ResourcePath) -> Result<Contact, CoreError>;
async fn create(&self, draft: &ContactDraft) -> Result<ResourcePath, CoreError>;
async fn update(
&self,
path: &ResourcePath,
etag: &ETag,
update: &ContactUpdate,
) -> Result<ETag, CoreError>;
async fn delete(&self, path: &ResourcePath, etag: &ETag) -> Result<(), CoreError>;
async fn set_group_membership(
&self,
group: &ResourcePath,
contact: &ResourcePath,
change: GroupChange,
) -> Result<(), CoreError>;
}