//! Parse command-line arguments.

use std::path::PathBuf;

use clap::Parser;

use crate::app::TabKind;
use crate::config;

const VERSION: &str = concat!("v", env!("CARGO_PKG_VERSION"));

#[derive(Parser, Default)]
#[clap(name = "wiremix", about = "PipeWire mixer")]
#[command(version = VERSION)]
pub struct Opt {
    /// Override default config file path
    #[clap(short = 'c', long, value_name = "FILE")]
    pub config: Option<PathBuf>,

    /// The name of the remote to connect to
    #[clap(short, long, value_name = "NAME")]
    pub remote: Option<String>,

    /// Target frames per second (or 0 for unlimited)
    #[clap(short, long)]
    pub fps: Option<f32>,

    /// Character set to use [built-in sets: default, compat, extracompat]
    #[clap(short = 's', long, value_name = "NAME")]
    pub char_set: Option<String>,

    /// Theme to use [built-in themes: default, nocolor, plain]
    #[clap(short, long, value_name = "NAME")]
    pub theme: Option<String>,

    /// Audio peak meters
    #[clap(short, long, value_parser = clap::value_parser!(config::Peaks))]
    pub peaks: Option<config::Peaks>,

    /// Disable mouse support
    #[clap(long, conflicts_with = "mouse")]
    pub no_mouse: bool,

    /// Enable mouse support
    #[clap(long, conflicts_with = "no_mouse")]
    pub mouse: bool,

    /// Initial tab view
    #[clap(
        short = 'v',
        long,
        value_enum,
        value_parser = clap::value_parser!(TabKind),
    )]
    pub tab: Option<TabKind>,

    /// Maximum volume for volume sliders
    #[clap(short = 'm', long, value_name = "PERCENT")]
    pub max_volume_percent: Option<f32>,

    /// Allow increasing volume past max-volume-percent
    #[clap(long, conflicts_with = "enforce_max_volume")]
    pub no_enforce_max_volume: bool,

    /// Prevent increasing volume past max-volume-percent
    #[clap(long, conflicts_with = "no_enforce_max_volume")]
    pub enforce_max_volume: bool,

    /// Monitor peak levels of all nodes
    #[clap(long, conflicts_with = "lazy_capture")]
    pub no_lazy_capture: bool,

    /// Only monitor peak levels of on-screen nodes (reduces CPU usage, but
    /// peaks appear with a slight delay)
    #[clap(long, conflicts_with = "no_lazy_capture")]
    pub lazy_capture: bool,

    #[cfg(debug_assertions)]
    #[clap(short, long)]
    pub dump_events: bool,
}

impl Opt {
    pub fn parse() -> Self {
        <Self as Parser>::parse()
    }
}
