use skeletor::{SkeletorConfig, apply_config};
use std::path::Path;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Example of using Skeletor as a library
    println!("🦀 Testing Skeletor Library API\n");
    
    // Create a configuration programmatically
    let config = SkeletorConfig::from_yaml_str(r#"
directories:
  my_rust_project:
    src:
      main.rs: |
        fn main() {
            println!("Hello from Skeletor library!");
        }
      lib.rs: |
        //! My awesome library
        
        pub fn greet(name: &str) -> String {
            format!("Hello, {}!", name)
        }
    tests:
      integration_test.rs: |
        use my_rust_project::greet;
        
        #[test]
        fn test_greet() {
            assert_eq!(greet("World"), "Hello, World!");
        }
    Cargo.toml: |
      [package]
      name = "my_rust_project"
      version = "0.1.0"
      edition = "2021"
      
      [dependencies]
    README.md: |
      # My Rust Project
      
      A project generated by Skeletor library!
"#)?;

    // Apply the configuration
    let target_dir = Path::new("./example_output");
    std::fs::create_dir_all(target_dir)?;
    
    println!("🚀 Generating project structure...");
    let result = apply_config(&config, target_dir, true, false)?;
    
    println!("✅ Success!");
    println!("   Files created: {}", result.files_created);
    println!("   Directories created: {}", result.dirs_created);
    println!("   Total tasks: {}", result.tasks_total);
    println!("   Duration: {:.2}ms", result.duration.as_micros() as f64 / 1000.0);
    
    // Clean up
    std::fs::remove_dir_all(target_dir)?;
    
    Ok(())
}