//! Plain-text rendering for `koala-core workflow size`. Pure function
//! so the CLI can be exercised without spawning a subprocess.

use crate::gates::{gates_for, Gate};
use crate::size::{DiffSummary, Size};
use std::fmt::Write as _;

pub fn render_size_report(summary: &DiffSummary, size: Size) -> String {
    let mut out = String::with_capacity(512);
    let _ = writeln!(out, "PR size: {size}");
    out.push('\n');
    let _ = writeln!(out, "  files changed:      {}", summary.files_changed);
    let _ = writeln!(out, "  LOC changed:        {}", summary.loc_changed);
    if !summary.crates_touched.is_empty() {
        let _ = writeln!(
            out,
            "  crates touched:     {}",
            summary.crates_touched.join(", ")
        );
    }
    let _ = writeln!(
        out,
        "  touches arch:       {}",
        summary.touches_architecture
    );
    let _ = writeln!(out, "  touches public API: {}", summary.touches_public_api);
    let _ = writeln!(out, "  all tests:          {}", summary.all_tests);
    out.push('\n');
    let gates: Vec<Gate> = gates_for(size);
    let _ = writeln!(out, "Required gates ({}):", size);
    for g in &gates {
        let mark = if g.blocking { "✗" } else { "•" };
        let _ = writeln!(
            out,
            "  {mark} {id:<28} — {intent}",
            id = g.id,
            intent = g.intent
        );
    }
    out
}
