use std::path::PathBuf;

use clap::Args;
use obikindex::KmerIndex;
use obisys::{Reporter, Stage};
use tracing::info;

#[derive(Args)]
pub struct PackArgs {
    /// Index directory to pack
    pub index: PathBuf,
}

pub fn run(args: PackArgs) {
    let idx = KmerIndex::open(&args.index).unwrap_or_else(|e| {
        eprintln!("error opening index: {e}");
        std::process::exit(1);
    });

    info!(
        "pack: {} partition(s), {} genome(s)",
        idx.n_partitions(),
        idx.meta().genomes.len(),
    );

    let mut rep = Reporter::new();
    let t = Stage::start("pack");

    idx.pack_matrices().unwrap_or_else(|e| {
        eprintln!("pack error: {e}");
        std::process::exit(1);
    });

    rep.push(t.stop());
    rep.print();
}
