use std::{sync::Arc, time::Duration};

use clap::{Parser, Subcommand};
use discretionary_engine_risk::config::{LiveSettings, SettingsFlags};

mod balance;
mod risk_layers;
mod size;

#[derive(Default, Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
	#[command(subcommand)]
	command: Commands,
	#[command(flatten)]
	settings: SettingsFlags,
}
#[derive(Subcommand)]
enum Commands {
	Size(size::SizeArgs),
	Balance,
}
impl Default for Commands {
	fn default() -> Self {
		Commands::Size(size::SizeArgs::default())
	}
}

#[tokio::main]
async fn main() {
	v_utils::clientside!();
	let cli = Cli::parse();
	let live_settings = match LiveSettings::new(cli.settings, Duration::from_secs(5)) {
		Ok(ls) => Arc::new(ls),
		Err(e) => {
			eprintln!("Error reading config: {e}");
			for cause in e.chain().skip(1) {
				eprintln!("  Caused by: {cause}");
			}
			return;
		}
	};
	match cli.command {
		Commands::Size(args) => size::main(live_settings, args).await.unwrap(),
		Commands::Balance => balance::main(live_settings).await.unwrap(),
	}
}
