//! Tree Index Module — Phase-90
//!
//! Provides tree-based document indexing for hierarchical retrieval,
//! inspired by [PageIndex](https://github.com/VectifyAI/PageIndex).
//!
//! # Architecture
//!
//! ```text
//! ┌───────────────────────────────────────────────────────────┐
//! │                    tree_index Module                       │
//! ├───────────────┬───────────────┬───────────────┬───────────┤
//! │   types.rs    │ md_parser.rs  │ thinning.rs   │ store.rs  │
//! │   Data Model  │ MD → Tree     │ Node Merge    │ Graph I/O │
//! ├───────────────┤               │               ├───────────┤
//! │  json_io.rs   │               │               │           │
//! │  JSON ↔ Tree  │               │               │           │
//! └───────────────┴───────────────┴───────────────┴───────────┘
//! ```
//!
//! # Key Types
//!
//! - [`TreeDocument`]: Complete tree-indexed document (metadata + tree structure).
//! - [`TreeNode`]: A node in the tree (section/heading with content and children).
//! - [`TreeMetadata`]: Document metadata (name, source, timestamps).
//! - [`NodeContent`]: Text content of a node with token count.
//! - [`TreeIndexConfig`]: Configuration for parsing and thinning.
//! - [`TreeIndexStore`]: Persistent storage backed by SocialGraphV2.
//! - [`MarkdownTreeParser`]: Parses Markdown into tree structure.
//!
//! # Usage
//!
//! ```ignore
//! use aifastdb_core::tree_index::{MarkdownTreeParser, TreeIndexStore, TreeDocument};
//! use std::sync::Arc;
//!
//! // Parse a Markdown document
//! let parser = MarkdownTreeParser::new();
//! let roots = parser.parse("# Chapter 1\nContent\n## Section 1.1\nMore content").unwrap();
//!
//! // Create a TreeDocument
//! let doc = TreeDocument::new(
//!     TreeMetadata::new("my-doc"),
//!     roots,
//! );
//!
//! // Store in graph
//! let store = TreeIndexStore::new(graph_store);
//! store.import_tree(&doc).unwrap();
//!
//! // Retrieve
//! let retrieved = store.get_tree(&doc.id).unwrap();
//! println!("TOC:\n{}", retrieved.table_of_contents());
//! ```

pub mod types;
pub mod md_parser;
pub mod thinning;
pub mod store;
pub mod json_io;
pub mod dynamic;

// Re-export primary types
pub use types::{
    TreeDocument, TreeNode, TreeMetadata, NodeContent,
    TreeIndexConfig, TreeIndexError, TreeIndexResult,
    tree_entity_types, tree_relation_types, tree_property_keys,
    estimate_tokens,
    // Phase-95: Dynamic Tree Index types
    NodeAccessStats, DynamicTreeConfig, ScanReport,
    DemoteReport, PromoteReport,
};

pub use md_parser::MarkdownTreeParser;
pub use thinning::{apply_thinning, recompute_token_counts};
pub use store::TreeIndexStore;
pub use json_io::{
    import_from_json, import_from_pageindex_json, import_from_file,
    export_to_json, export_to_pageindex_json, export_to_file,
    PageIndexJson, PageIndexNodeJson,
};
pub use dynamic::DynamicTreeManager;