/// Example demonstrating companion packages functionality
/// 
/// This example shows how companion packages are automatically
/// installed and uninstalled together with the main package.

use libarc::{ArcConfig, PackageManager};

fn main() {
    println!("Companion Packages Demo\n");
    println!("========================\n");

    // Create a custom config with companion packages
    let mut config = ArcConfig::default();
    
    // Configure Steam with companion packages
    config.pacman_companions.insert(
        "steam".to_string(),
        vec![
            "steam-native-runtime".to_string(),
            "lib32-nvidia-utils".to_string(),
        ]
    );
    
    // Configure Wine with companion packages
    config.pacman_companions.insert(
        "wine".to_string(),
        vec![
            "wine-mono".to_string(),
            "wine-gecko".to_string(),
        ]
    );
    
    // Configure Blender with optional GPU support
    config.pacman_companions.insert(
        "blender".to_string(),
        vec![
            "cuda".to_string(),
            "optix".to_string(),
        ]
    );
    
    // Whitelist all packages
    config.pacman_whitelist = vec![
        "steam".to_string(),
        "steam-native-runtime".to_string(),
        "lib32-nvidia-utils".to_string(),
        "wine".to_string(),
        "wine-mono".to_string(),
        "wine-gecko".to_string(),
        "blender".to_string(),
        "cuda".to_string(),
        "optix".to_string(),
    ];

    let pm = PackageManager::with_config(config);

    // Display configured companion packages
    println!("Configured companion packages:\n");
    
    let packages = vec!["steam", "wine", "blender"];
    for pkg in packages {
        let companions = pm.config().get_companion_packages(pkg);
        if companions.is_empty() {
            println!("  {} → no companions", pkg);
        } else {
            println!("  {} →", pkg);
            for companion in companions {
                println!("    - {}", companion);
            }
        }
    }
    println!();

    // Demonstrate installation behavior
    println!("Installation behavior:");
    println!("  When you install 'steam', the following will be installed:");
    println!("    1. steam (main package)");
    println!("    2. steam-native-runtime (companion)");
    println!("    3. lib32-nvidia-utils (companion)");
    println!();

    println!("Uninstallation behavior:");
    println!("  When you uninstall 'steam', the following will be uninstalled:");
    println!("    1. steam-native-runtime (companion, removed first)");
    println!("    2. lib32-nvidia-utils (companion, removed first)");
    println!("    3. steam (main package, removed last)");
    println!();

    // Show practical use case
    println!("Use cases for companion packages:");
    println!("  • Dependencies: Automatically install required libraries");
    println!("  • Optional features: Install GPU support, codec packs, etc.");
    println!("  • Related tools: Install package managers with interpreters");
    println!("  • Hardware support: Install drivers with main application");
    println!();

    println!("Note: Companion packages are also:");
    println!("  - Resolved through aliases (if configured)");
    println!("  - Checked against whitelist");
    println!("  - Skipped if not whitelisted (no error)");
    println!("  - Ignored on uninstall errors (might not be installed)");
}
