use colored::Colorize;
use lmrc_config_validator::LmrcConfig;
use std::path::PathBuf;

use crate::error::Result;

pub async fn execute(config: String) -> Result<()> {
    println!("{} {}", "Validating configuration:".yellow(), config.cyan());

    let config_path = PathBuf::from(config);
    let parsed_config = LmrcConfig::from_file(&config_path)?;

    println!("{}", "Configuration is valid!".green().bold());
    println!("\nProject: {}", parsed_config.project.name.cyan());
    println!("Description: {}", parsed_config.project.description);
    println!("\nProviders:");
    println!("  Server: {}", parsed_config.providers.server);
    println!("  Kubernetes: {}", parsed_config.providers.kubernetes);
    println!("  Database: {}", parsed_config.providers.database);
    println!("  DNS: {}", parsed_config.providers.dns);
    println!("  Git: {}", parsed_config.providers.git);
    println!("\nApplications: {}", parsed_config.apps.applications.len());
    for app in &parsed_config.apps.applications {
        println!("  - {} ({})", app.name, app.app_type);
    }

    Ok(())
}
