mod strategies;

use anyhow::Result;
use clap::Parser;

#[derive(Parser)]
#[command(name = "obliq")]
#[command(about = "Oblique Strategies by Brian Eno and Peter Schmidt, in your terminal", long_about = None)]
#[command(version)]
struct Cli {
    /// Edition to use (1-4)
    #[arg(short, long, default_value = "4", value_parser = clap::value_parser!(u8).range(1..=4))]
    edition: u8,

    /// List all strategies in the selected edition
    #[arg(short, long)]
    list: bool,
}

fn main() -> Result<()> {
    let cli = Cli::parse();

    let edition = strategies::load_edition(cli.edition)?;

    if cli.list {
        println!(
            "Oblique Strategies - Edition {} ({})",
            edition.edition, edition.year
        );
        println!("By Brian Eno and Peter Schmidt\n");
        for (i, strategy) in edition.strategies.iter().enumerate() {
            println!("{}. {}", i + 1, strategy);
        }
        println!("\nTotal: {} strategies", edition.strategies.len());
    } else {
        let strategy = strategies::random_strategy(&edition);
        println!("{}", strategy);
    }

    Ok(())
}
