//! Build-time Path Resolution Wrapper
//!
//! This module provides a build-time wrapper around the unified path resolution
//! system from the utils crate. This ensures consistent path handling
//! across all build scripts and tools.

use std::path::PathBuf;

/// Re-export types from unified utils crate
pub use rustelo_utils::{PathContext, PathResolver, SitePaths};

/// Convenience function to create a path resolver and get site paths for build-time use
pub fn get_resolved_site_paths() -> Result<SitePaths, Box<dyn std::error::Error>> {
    let resolver = PathResolver::new_with_context(PathContext::BuildTime)?;
    Ok(resolver.get_site_paths()?)
}

/// Convenience function to resolve a single SITE_* environment variable for build-time use
pub fn resolve_site_env_var(
    env_var: &str,
    default: &str,
) -> Result<PathBuf, Box<dyn std::error::Error>> {
    let resolver = PathResolver::new_with_context(PathContext::BuildTime)?;
    let path_str = resolver.resolve_site_path(env_var, default)?;
    Ok(PathBuf::from(path_str))
}

/// Build-time specific convenience functions that return PathBuf for compatibility
pub fn get_content_path() -> PathBuf {
    PathBuf::from(rustelo_utils::get_content_path())
}

pub fn get_config_path() -> PathBuf {
    PathBuf::from(rustelo_utils::get_config_path())
}

pub fn get_i18n_path() -> PathBuf {
    PathBuf::from(rustelo_utils::get_i18n_path())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_build_time_path_resolver() {
        // Test that we can create a build-time resolver
        let resolver = PathResolver::new_with_context(PathContext::BuildTime);
        assert!(resolver.is_ok());
    }

    #[test]
    fn test_site_paths_resolution() {
        // Test build-time path resolution works
        if let Ok(_paths) = get_resolved_site_paths() {
            // SitePaths now contains Strings, not PathBufs
            // Just verify we can get the paths without error
        }
    }

    #[test]
    fn test_convenience_functions() {
        // Test convenience functions work
        let content_path = get_content_path();
        let config_path = get_config_path();
        let i18n_path = get_i18n_path();

        assert!(content_path.is_absolute());
        assert!(config_path.is_absolute());
        assert!(i18n_path.is_absolute());
    }
}
