//! Demonstrates scale-adaptive promotion thresholds.
//!
//! Run with: `cargo run --example scale_adaptive_demo`

use aphoria::corpus::thresholds::{ScaleAdaptiveThresholds, ScaleTier};

fn main() {
    println!("=== Scale-Adaptive Promotion Thresholds Demo ===\n");

    let thresholds = ScaleAdaptiveThresholds::default();

    // Scenario 1: Micro Team (3 projects)
    println!("📊 Scenario 1: Micro Team (3 projects)");
    println!("Pattern appears in 2 out of 3 projects (67% adoption)\n");

    let tier = ScaleTier::from_total_projects(3);
    println!("  Scale Tier: {:?}", tier);

    let decision = thresholds.evaluate(2, 3, false, None);
    println!("  Decision: {:?}", decision);
    println!("  ✅ Pattern VISIBLE to team (RequireReview)\n");

    // Scenario 2: Small Team with RFC match
    println!("📊 Scenario 2: Small Team (10 projects)");
    println!("Pattern appears in 9 projects with RFC match (90% adoption)\n");

    let tier = ScaleTier::from_total_projects(10);
    println!("  Scale Tier: {:?}", tier);

    let decision = thresholds.evaluate(9, 10, true, Some("rfc://5246"));
    println!("  Decision: {:?}", decision);
    println!("  ✅ Auto-promoted to Regulatory tier\n");

    // Scenario 3: Enterprise (1000 projects)
    println!("📊 Scenario 3: Enterprise (1000 projects)");
    println!("Pattern appears in 950 projects with RFC match (95% adoption)\n");

    let tier = ScaleTier::from_total_projects(1000);
    println!("  Scale Tier: {:?}", tier);

    let decision = thresholds.evaluate(950, 1000, true, Some("rfc://9110"));
    println!("  Decision: {:?}", decision);
    println!("  ✅ Auto-promoted to Regulatory tier (backward compatible)\n");

    // Scenario 4: Noise prevention
    println!("📊 Scenario 4: Noise Prevention (3 projects)");
    println!("Pattern appears in only 1 project (33% adoption)\n");

    let tier = ScaleTier::from_total_projects(3);
    println!("  Scale Tier: {:?}", tier);

    let decision = thresholds.evaluate(1, 3, false, None);
    println!("  Decision: {:?}", decision);
    println!("  ✅ Skipped (floor prevents single-project noise)\n");

    // Show threshold matrix
    println!("=== Threshold Matrix ===\n");
    println!("| Tier       | Projects | Emerging Floor | Regulatory Floor |");
    println!("|------------|----------|----------------|------------------|");

    for (name, total) in [
        ("Micro", 3),
        ("Small", 10),
        ("Medium", 50),
        ("Large", 200),
        ("Enterprise", 1000),
    ] {
        let tier = ScaleTier::from_total_projects(total);
        let tier_thresholds = thresholds.for_tier(tier);

        let emerging_min = tier_thresholds.emerging.effective_min_projects(total);

        let regulatory_min = if let Some(reg) = &tier_thresholds.regulatory {
            format!("{}", reg.effective_min_projects(total))
        } else {
            "N/A".to_string()
        };

        println!(
            "| {:10} | {:8} | {:14} | {:16} |",
            name, total, emerging_min, regulatory_min
        );
    }

    println!("\n✅ Small teams see value immediately!");
    println!("✅ Quality maintained via floors and adoption rates!");
    println!("✅ Enterprise behavior unchanged!");
}
