use crate::channels::{BindBodyError, BindInitiate, BindUpdateBody};
use crate::client::Links;
use crate::errors::SemiontError;
use crate::transport::Envelope;
use crate::types::{AnnotationId, ResourceId};
use crate::types::{
BindBodyOperation, BindInitiateCommand, BindUpdateBodyCommand, ResourceErrorEvent,
};
pub struct BindNamespace {
links: Links,
}
impl BindNamespace {
pub(crate) fn new(links: Links) -> BindNamespace {
BindNamespace { links }
}
pub async fn body(
&self,
resource_id: &ResourceId,
annotation_id: &AnnotationId,
operations: Vec<BindBodyOperation>,
) -> Result<(), SemiontError> {
self.links
.request::<BindUpdateBody>(&BindUpdateBodyCommand {
_user_id: None,
annotation_id: annotation_id.clone(),
resource_id: resource_id.clone(),
operations,
})
.await?;
Ok(())
}
pub fn initiate(&self, input: BindInitiateCommand) {
self.links
.signal::<BindInitiate>(&input, Envelope::default());
}
pub fn report_body_error(&self, input: ResourceErrorEvent) {
self.links
.signal::<BindBodyError>(&input, Envelope::default());
}
}