use std::path::PathBuf;
use crate::document::DocumentTree;
use crate::index::parse::DocumentFormat;
use crate::metrics::IndexMetrics;
use crate::storage::PageContent;
#[derive(Debug, Clone)]
pub(crate) struct IndexedDocument {
pub id: String,
pub format: DocumentFormat,
pub name: String,
pub description: Option<String>,
pub source_path: Option<PathBuf>,
pub page_count: Option<usize>,
pub tree: Option<DocumentTree>,
pub pages: Vec<PageContent>,
pub metrics: Option<IndexMetrics>,
pub reasoning_index: Option<crate::document::ReasoningIndex>,
pub navigation_index: Option<crate::document::NavigationIndex>,
}
impl IndexedDocument {
pub fn new(id: impl Into<String>, format: DocumentFormat) -> Self {
Self {
id: id.into(),
format,
name: String::new(),
description: None,
source_path: None,
page_count: None,
tree: None,
pages: Vec::new(),
metrics: None,
reasoning_index: None,
navigation_index: None,
}
}
pub fn with_name(mut self, name: impl Into<String>) -> Self {
self.name = name.into();
self
}
pub fn with_description(mut self, desc: impl Into<String>) -> Self {
self.description = Some(desc.into());
self
}
pub fn with_source_path(mut self, path: impl Into<PathBuf>) -> Self {
self.source_path = Some(path.into());
self
}
pub fn with_page_count(mut self, count: usize) -> Self {
self.page_count = Some(count);
self
}
pub fn with_tree(mut self, tree: DocumentTree) -> Self {
self.tree = Some(tree);
self
}
pub fn with_metrics(mut self, metrics: IndexMetrics) -> Self {
self.metrics = Some(metrics);
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_indexed_document() {
let doc = IndexedDocument::new("doc-1", DocumentFormat::Markdown)
.with_name("Test Document")
.with_description("A test document");
assert_eq!(doc.id, "doc-1");
assert_eq!(doc.name, "Test Document");
assert!(doc.tree.is_none());
}
}