use std::collections::HashMap;

use secrecy::SecretString;
use v_utils::{Percent, macros as v_macros, percent::PercentU};

#[derive(Clone, Debug, Default, v_macros::LiveSettings, v_macros::MyConfigPrimitives, v_macros::Settings)]
pub struct AppConfig {
	#[settings(flatten)]
	pub size: Option<SizeConfig>,
	#[settings(skip)]
	pub exchanges: HashMap<String, ExchangeConfig>,
	pub other_balances: Option<f64>,
}

#[derive(Clone, Debug, Default, v_macros::MyConfigPrimitives, v_macros::SettingsNested)]
pub struct SizeConfig {
	pub default_sl: Percent,
	#[settings(default = "PercentU::new(0.01).unwrap()")]
	pub round_bias: PercentU,
	/// Max risk for A-quality trades. Each tier below divides by e (2.718...)
	pub abs_max_risk: Percent,
	#[settings(flatten)]
	pub risk_layers: Option<RiskLayersConfig>,
}

#[derive(Clone, Debug, Default, v_macros::MyConfigPrimitives, v_macros::SettingsNested)]
pub struct RiskLayersConfig {
	#[settings(default = "true")]
	pub stop_loss_proximity: bool,
	#[settings(default = "false")]
	pub from_phone: bool,
	#[settings(default = "false")]
	pub lost_last_trade: bool,
}

#[derive(Clone, Debug, v_macros::MyConfigPrimitives)]
pub struct ExchangeConfig {
	pub api_pubkey: String,
	pub api_secret: SecretString,
	#[serde(default)]
	pub passphrase: Option<SecretString>,
}
