//! Version Control Module
//!
//! Provides a unified interface for content version control with support for
//! different storage backends (file-based, database-based, etc.)

#[cfg(feature = "content-db")]
pub mod database_backend;
pub mod file_backend;
pub mod models;
pub mod traits;
pub mod utils;

// Re-export the main types
// Re-export backend implementations
#[cfg(feature = "content-db")]
pub use database_backend::DatabaseVersionControlBackend;
pub use file_backend::FileVersionControlBackend;
pub use models::{ContentVersion, VersionDiff, VersionHistory};
pub use traits::{VersionControlBackend, VersionControlManager};

/// Factory for creating version control managers based on storage type
pub struct VersionControlFactory;

impl VersionControlFactory {
    /// Create a file-based version control manager
    #[cfg(feature = "content-static")]
    pub fn create_file_backend<P: AsRef<std::path::Path>>(
        content_root: P,
    ) -> Box<dyn VersionControlBackend + Send + Sync> {
        Box::new(FileVersionControlBackend::new(content_root))
    }

    /// Create a database-based version control manager
    #[cfg(feature = "content-db")]
    pub fn create_database_backend(
        connection: std::sync::Arc<crate::database::DatabaseConnection>,
    ) -> Box<dyn VersionControlBackend + Send + Sync> {
        Box::new(DatabaseVersionControlBackend::new(connection))
    }

    /// Create version control manager based on content source type
    pub fn create_for_source(
        source: &crate::content::ContentSource,
        #[cfg(feature = "content-static")] content_root: Option<std::path::PathBuf>,
        #[cfg(feature = "content-db")] database: Option<
            std::sync::Arc<crate::database::DatabaseConnection>,
        >,
    ) -> Option<Box<dyn VersionControlBackend + Send + Sync>> {
        match source {
            #[cfg(feature = "content-static")]
            crate::content::ContentSource::Files | crate::content::ContentSource::Both => {
                content_root.map(|root| Self::create_file_backend(root))
            }
            #[cfg(feature = "content-db")]
            crate::content::ContentSource::Database => {
                database.map(|db| Self::create_database_backend(db))
            }
            #[cfg(not(feature = "content-db"))]
            crate::content::ContentSource::Database => None,
            #[cfg(not(any(feature = "content-static", feature = "content-db")))]
            _ => None,
        }
    }
}
