use crate::channels::{BeckonFocus, BeckonHover, BeckonSparkle, BrowseClick, BrowseResourceOpen};
use crate::client::Links;
use crate::errors::SemiontError;
use crate::transport::Envelope;
use crate::types::{AnnotationId, ResourceId};
use crate::types::{
BeckonFocusEvent, BeckonHoverEvent, BeckonSparkleEvent, BrowseClickEvent,
BrowseResourceOpenEvent,
};
pub struct BeckonNamespace {
links: Links,
}
impl BeckonNamespace {
pub(crate) fn new(links: Links) -> BeckonNamespace {
BeckonNamespace { links }
}
pub async fn attention(
&self,
resource_id: &ResourceId,
annotation_id: Option<&AnnotationId>,
) -> Result<Option<u64>, SemiontError> {
self.links
.drive::<BeckonFocus>(&BeckonFocusEvent {
annotation_id: annotation_id.cloned(),
resource_id: resource_id.clone(),
})
.await
}
pub async fn click(&self, annotation_id: &AnnotationId) -> Result<Option<u64>, SemiontError> {
self.links
.drive::<BrowseClick>(&BrowseClickEvent {
annotation_id: annotation_id.clone(),
})
.await
}
pub async fn open_resource(
&self,
resource_id: &ResourceId,
) -> Result<Option<u64>, SemiontError> {
self.links
.drive::<BrowseResourceOpen>(&BrowseResourceOpenEvent {
resource_id: resource_id.clone(),
})
.await
}
pub async fn sparkle_all(
&self,
annotation_id: &AnnotationId,
) -> Result<Option<u64>, SemiontError> {
self.links
.drive::<BeckonSparkle>(&BeckonSparkleEvent {
annotation_id: annotation_id.clone(),
})
.await
}
pub fn hover(&self, annotation_id: Option<&AnnotationId>) {
self.links.signal::<BeckonHover>(
&BeckonHoverEvent {
annotation_id: annotation_id.cloned(),
},
Envelope::default(),
);
}
pub fn sparkle(&self, annotation_id: &AnnotationId) {
self.links.signal::<BeckonSparkle>(
&BeckonSparkleEvent {
annotation_id: annotation_id.clone(),
},
Envelope::default(),
);
}
}