use std::sync::Arc;
use adk_core::AdkError;
use adk_kernel::pairing::DeviceStore;
pub(crate) use adk_kernel::pairing::{AttachmentHolder as Holder, DeviceAttachment as Attachment};
pub(crate) const PUSH: &str = "push";
pub(crate) const PUSH_KEY: &str = "subscription";
pub(crate) const PASSKEY: &str = "passkey";
pub(crate) const DEVICE_PASSKEY_KEY: &str = "passkey";
pub(crate) const WAKE: &str = "wake";
#[derive(Clone)]
pub(crate) struct Attachments(Arc<dyn DeviceStore>);
impl Attachments {
pub(crate) fn new(store: Arc<dyn DeviceStore>) -> Self {
Self(store)
}
pub(crate) async fn put(&self, attachment: Attachment) -> Result<(), AdkError> {
self.0.put_attachment(attachment).await.map_err(AdkError::from)
}
pub(crate) async fn put_if_absent(&self, attachment: Attachment) -> Result<bool, AdkError> {
self.0.put_attachment_if_absent(attachment).await.map_err(AdkError::from)
}
pub(crate) async fn list(
&self,
holder: &Holder,
kind: &str,
) -> Result<Vec<Attachment>, AdkError> {
self.0.attachments(holder, kind).await.map_err(AdkError::from)
}
pub(crate) async fn remove(
&self,
holder: &Holder,
kind: &str,
key: &str,
) -> Result<bool, AdkError> {
self.0.remove_attachment(holder, kind, key).await.map_err(AdkError::from)
}
pub(crate) async fn remove_all(&self, holder: &Holder) -> Result<usize, AdkError> {
self.0.remove_attachments(holder).await.map_err(AdkError::from)
}
}