//! Dependency resolution testing

use anyhow::Result;
use std::collections::HashMap;

use crate::helpers::TestFeatureBuilder;

#[test]
fn test_simple_dependency_resolution() -> Result<()> {
    // Test basic dependency resolution without cycles
    let temp_project = crate::create_test_project()?;
    let project_root = temp_project.path();

    // Feature A depends on nothing
    let feature_a = TestFeatureBuilder::new("base-feature");
    feature_a.create_in_project(project_root)?;

    // Feature B depends on A
    let feature_b = TestFeatureBuilder::new("dependent-feature")
        .with_dependency("base-feature");
    feature_b.create_in_project(project_root)?;

    // Expected resolution order: [base-feature, dependent-feature]
    // This would be tested with actual DependencyResolver

    Ok(())
}

#[test]
fn test_circular_dependency_detection() -> Result<()> {
    let temp_project = crate::create_test_project()?;
    let project_root = temp_project.path();

    // Create circular dependency: A -> B -> A
    let feature_a = TestFeatureBuilder::new("circular-a")
        .with_dependency("circular-b");
    feature_a.create_in_project(project_root)?;

    let feature_b = TestFeatureBuilder::new("circular-b")
        .with_dependency("circular-a");
    feature_b.create_in_project(project_root)?;

    // Test that circular dependency is detected
    // This would use DependencyResolver and expect an error

    Ok(())
}

#[test]
fn test_complex_dependency_graph() -> Result<()> {
    let temp_project = crate::create_test_project()?;
    let project_root = temp_project.path();

    // Create complex dependency graph:
    // D -> B, C
    // B -> A
    // C -> A
    // Expected order: A, B, C, D

    let feature_a = TestFeatureBuilder::new("core");
    feature_a.create_in_project(project_root)?;

    let feature_b = TestFeatureBuilder::new("auth")
        .with_dependency("core");
    feature_b.create_in_project(project_root)?;

    let feature_c = TestFeatureBuilder::new("content")
        .with_dependency("core");
    feature_c.create_in_project(project_root)?;

    let feature_d = TestFeatureBuilder::new("full-stack")
        .with_dependency("auth")
        .with_dependency("content");
    feature_d.create_in_project(project_root)?;

    // Test resolution order
    // This would use actual DependencyResolver

    Ok(())
}
