//! Federation Module - Heterogeneous Storage Federation
//!
//! This module provides a unified interface for federating multiple storage types:
//! - Graph stores (SocialStoreV2)
//! - Document stores (EnhancedDocumentStore)
//! - Vector stores (ConcurrentHNSWIndex)
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────┐
//! │                     Federation (主入口)                      │
//! ├─────────────────────────────────────────────────────────────┤
//! │  register_graph()   register_document()   register_vector() │
//! │  use_graph()        use_doc()             use_vector()      │
//! │  query()            batch_write()         begin_transaction()│
//! └─────────────────────────────────────────────────────────────┘
//!                              │
//!          ┌───────────────────┼───────────────────┐
//!          ▼                   ▼                   ▼
//! ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
//! │GraphStoreAdapter│ │DocumentStoreAdapter│ │VectorStoreAdapter│
//! │ (impl Store)    │ │ (impl Store)    │ │ (impl Store)    │
//! └─────────────────┘ └─────────────────┘ └─────────────────┘
//! ```
//!
//! # Example
//!
//! ```rust,ignore
//! use aifastdb_core::federation::{Federation, FederationConfig};
//!
//! let federation = Federation::new(FederationConfig::default())?;
//!
//! // Register stores
//! federation.register_graph("social", social_store)?;
//! federation.register_document("knowledge", doc_store)?;
//!
//! // Type-safe access
//! let social = federation.use_graph("social")?;
//! let knowledge = federation.use_doc("knowledge")?;
//!
//! // Cross-store query
//! let result = federation.query(query).await?;
//! ```

// Core traits and types
pub mod traits;
pub mod types;
pub mod error;

// Store adapters
pub mod adapters;

// Core components
pub mod federation;
pub mod cross_db_index;
pub mod query_planner;
pub mod query_executor;
pub mod transaction;
pub mod ref_resolver;

// Production capabilities (§8.5 ~ §8.10)
pub mod resilience;
pub mod permission;
pub mod record_permission;
pub mod metrics;
pub mod rate_limiter;
pub mod reaper;
pub mod backup;
pub mod benchmark;

// Re-exports
pub use traits::{Store, LocalTransaction, AsAny};
pub use types::{
    StoreType, Record, WriteOp, WriteResult, BatchWriteResult,
    UniversalQuery, Filter, SortOrder, TraverseSpec,
    EntityLocation, TypeCrossRelation, CrossDbQuery, QueryResult,
    QueryTarget, JoinClause, JoinType, JoinStrategy,
    // Ownership & Permission types (§8.5.7)
    Visibility, RecordPermission, Collaborator, OwnershipMeta,
    ProtectionLevel, SYSTEM_OWNER_ID,
};
pub use error::{FederationError, Result};
pub use federation::{Federation, FederationConfig};
pub use cross_db_index::CrossDbIndex;
pub use query_planner::QueryPlanner;
pub use transaction::{TransactionCoordinator, TransactionState, RecoveryResult};
pub use federation::FederatedTransaction;

// Production capability re-exports
pub use resilience::{
    CircuitBreaker, CircuitBreakerConfig, CircuitState,
    RetryExecutor, RetryConfig, RetryableError,
    TimeoutController, TimeoutConfig, OperationKind,
    ResilienceConfig,
};
pub use permission::{PermissionChecker, Permission, AccessContext};
pub use record_permission::{RecordPermissionChecker, RecordActions, ProtectionCheckResult};
pub use metrics::FederationMetrics;
pub use rate_limiter::{RateLimiter, RateLimitConfig};
pub use reaper::{TransactionReaper, ReaperConfig};
pub use backup::{FederationBackup, BackupManifest, BackupOptions, RestoreOptions, RetentionPolicy};
pub use benchmark::{FederationBenchmark, BenchmarkResult, BenchmarkConfig, BenchmarkReport};

// Adapter re-exports
pub use adapters::{GraphStoreAdapter, DocumentStoreAdapter, ConcurrentDocStoreAdapter, VectorStoreAdapter};
#[cfg(feature = "lance-storage")]
pub use adapters::LanceStoreAdapter;

#[cfg(test)]
mod tests;
