use crate::core::{IngestionOutcome, ScopeIdentifiers};
use crate::engine::NeomemxEngine;
use crate::error::{NeomemxError, Result};
use std::collections::HashMap;
pub type MetadataMap = HashMap<String, serde_json::Value>;
pub struct StorageBuilder {
engine: NeomemxEngine,
content: String,
scope: Option<ScopeIdentifiers>,
metadata: Option<MetadataMap>,
enable_extraction: bool,
enable_graph: bool,
}
impl StorageBuilder {
pub(crate) fn new(engine: NeomemxEngine, content: impl Into<String>) -> Self {
Self {
engine,
content: content.into(),
scope: None,
metadata: None,
enable_extraction: true,
enable_graph: false,
}
}
pub fn with_scope(mut self, scope: ScopeIdentifiers) -> Self {
self.scope = Some(scope);
self
}
pub fn with_metadata(mut self, metadata: MetadataMap) -> Self {
self.metadata = Some(metadata);
self
}
pub fn enable_extraction(mut self, enabled: bool) -> Self {
self.enable_extraction = enabled;
self
}
pub fn enable_graph(mut self, enabled: bool) -> Self {
self.enable_graph = enabled;
self
}
pub async fn execute(self) -> Result<IngestionOutcome> {
let scope = self.scope.ok_or_else(|| NeomemxError::required("scope"))?;
scope.validate()?;
self.engine
.store_internal(
&self.content,
scope,
self.metadata,
self.enable_extraction,
self.enable_graph,
)
.await
}
}