use clap::Args;

use super::index::resolve_approx_params;

#[derive(Args)]
pub struct EstimateArgs {
    /// k-mer size used for querying (same as --kmer-size in index)
    #[arg(short = 'k', long, default_value_t = 31)]
    pub kmer_size: usize,

    /// Findere z parameter: number of consecutive k-mers that must all match.
    /// Effective indexed k-mer size is kmer_size - z + 1.
    #[arg(short = 'z', long, default_value = None)]
    pub findere_z: Option<u8>,

    /// Fingerprint bits per slot (b).  FP per z-window = 1/2^(b·z).
    #[arg(long, default_value = None)]
    pub evidence_bits: Option<u8>,

    /// Target false-positive rate per z-window (e.g. 0.01).
    #[arg(long, default_value = None)]
    pub fp: Option<f64>,
}

pub fn run(args: EstimateArgs) {
    let (z, b, fp_window) = resolve_approx_params(args.findere_z, args.evidence_bits, args.fp);

    let k_query = args.kmer_size;
    let k_index = k_query.saturating_sub(z as usize - 1);
    let fp_kmer = 1.0_f64 / 2_f64.powi(b as i32);

    println!("{:<22} {}", "k (query):",        k_query);
    println!("{:<22} {}", "k (indexed):",      k_index);
    println!("{:<22} {}", "z:",                z);
    println!("{:<22} {}", "evidence bits (b):", b);
    println!("{:<22} {:.3e}  (1/2^{})",        "FP per k-mer:",    fp_kmer,   b);
    println!("{:<22} {:.3e}  (1/2^{})",        "FP per z-window:", fp_window, b as u32 * z as u32);
}
