use crate::{generate, genreqs};
use clap::{Parser, Subcommand};
use std::path::PathBuf;

#[derive(Parser)]
#[command(name = "Hagrid Tester", version, about, long_about = None, help_expected = true)]
pub(crate) struct Cli {
    #[command(subcommand)]
    command: Command,
}

#[derive(Subcommand)]
enum Command {
    /// generate requests
    GenReqs {
        #[arg(long = "fingerprints-file", default_value = "fingerprints.txt")]
        /// path to read fingerprints from
        fingerprints_file: PathBuf,
        /// host to generate requests for
        host: String,
    },
    /// Generate a test set of certificates
    Generate {
        #[arg(long, default_value_t = 100_000)]
        /// number of certificates to generate
        cert_count: u64,
        #[arg(long = "output-file", default_value = "keyring.pub.pgp")]
        /// path to file to store the certificates in
        certs_output_file: PathBuf,
        #[arg(long = "fingerprints-file", default_value = "fingerprints.txt")]
        /// path to file to store fingerprints in
        fingerprints_output_file: PathBuf,
    },
}

pub(crate) fn dispatch_cmd(cli: Cli) -> anyhow::Result<()> {
    match cli.command {
        Command::GenReqs {
            fingerprints_file,
            host,
        } => genreqs::run(&host, fingerprints_file),
        Command::Generate {
            cert_count,
            certs_output_file,
            fingerprints_output_file,
        } => generate::run(cert_count, certs_output_file, fingerprints_output_file),
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use clap::CommandFactory;

    #[test]
    fn test_cli() {
        Cli::command().debug_assert()
    }
}
