use pbap_core::client::PbapClient;
use pbap_core::phonebook::{PhonebookPath, SearchAttribute};
use pbap_core::{CardEntry, Contact};
use tokio::io::{AsyncRead, AsyncWrite};
pub async fn list<T: AsyncRead + AsyncWrite + Unpin>(
client: &mut PbapClient<T>,
path: PhonebookPath,
limit: Option<u16>,
offset: u16,
) -> anyhow::Result<Vec<CardEntry>> {
Ok(client.list(path, limit, offset).await?)
}
pub async fn get<T: AsyncRead + AsyncWrite + Unpin>(
client: &mut PbapClient<T>,
path: PhonebookPath,
handle: &str,
) -> anyhow::Result<Contact> {
Ok(client.pull(path, handle).await?)
}
pub async fn pull_all<T: AsyncRead + AsyncWrite + Unpin>(
client: &mut PbapClient<T>,
path: PhonebookPath,
limit: Option<u16>,
offset: u16,
) -> anyhow::Result<Vec<Contact>> {
Ok(client.pull_all(path, limit, offset).await?)
}
pub async fn lookup<T: AsyncRead + AsyncWrite + Unpin>(
client: &mut PbapClient<T>,
path: PhonebookPath,
number: &str,
) -> anyhow::Result<Option<Contact>> {
let entries = client.search(path, SearchAttribute::Number, number, None, 0).await?;
let Some(entry) = entries.iter().find(|e| e.handle() != "0.vcf") else {
return Ok(None);
};
Ok(Some(client.pull(path, entry.handle()).await?))
}
#[cfg(test)]
mod tests;