//! Validation: dump the parsed mission/phase cutscene map from the real manifest.
use sylpheed_formats::movie_manifest::{self, MovieKind};
use sylpheed_formats::pak::PakArchive;

fn main() {
    let disc = std::env::var("SYLPHEED_DISC").expect("set SYLPHEED_DISC");
    let arc = PakArchive::open(format!("{disc}/dat/tables.pak")).unwrap();
    let man = arc
        .entries()
        .iter()
        .find_map(|e| arc.read(e).ok().filter(|b| movie_manifest::is_manifest(b)))
        .expect("manifest");
    let entries = movie_manifest::parse(&man);
    let mut counts = [0usize; 5];
    for e in &entries {
        counts[match e.kind {
            MovieKind::System => 0,
            MovieKind::Intro => 1,
            MovieKind::Phase => 2,
            MovieKind::PhaseEnd => 3,
            MovieKind::Supply => 4,
        }] += 1;
        let m = e.mission.map(|x| x.to_string()).unwrap_or_default();
        let p = e.phase.map(|x| x.to_string()).unwrap_or_default();
        println!(
            "{:<22} {:<9} m={:<2} p={:<1} {:<16} {:<14} tel={:<14} sub={}",
            e.slot,
            format!("{:?}", e.kind),
            m,
            p,
            e.movie,
            e.voice_token.as_deref().unwrap_or("-"),
            e.telop.as_deref().unwrap_or("-"),
            e.subtitle.as_deref().unwrap_or("-"),
        );
    }
    eprintln!(
        "TOTAL {} entries — System={} Intro={} Phase={} PhaseEnd={} Supply={}",
        entries.len(),
        counts[0],
        counts[1],
        counts[2],
        counts[3],
        counts[4]
    );
}
