use std::path::PathBuf;

use selene_daemon::{daemon::DaemonError, player::Player};
pub use symphonia::core::errors::Error as SymphoniaError;

use clap::{Parser, ValueEnum};
use lunar_lib::log::{self, CliLogger};

const LOGGER: CliLogger = CliLogger;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum DaemonLevelFilter {
    Off,
    Error,
    Warn,
    Info,
    Debug,
    Trace,
}

impl From<DaemonLevelFilter> for log::LevelFilter {
    fn from(value: DaemonLevelFilter) -> Self {
        match value {
            DaemonLevelFilter::Off => log::LevelFilter::Off,
            DaemonLevelFilter::Error => log::LevelFilter::Error,
            DaemonLevelFilter::Warn => log::LevelFilter::Warn,
            DaemonLevelFilter::Info => log::LevelFilter::Info,
            DaemonLevelFilter::Debug => log::LevelFilter::Debug,
            DaemonLevelFilter::Trace => log::LevelFilter::Trace,
        }
    }
}

#[derive(Debug, Parser)]
#[command(version, about, long_about)]
struct Cli {
    /// Overide the desired config file destination. Defaults to `CONFIG_DIR/selene/daemon.toml`.
    #[arg(short = 'c', long = "config")]
    config_file: Option<PathBuf>,

    /// Override the desired log level. Defaults to `debug`.
    #[arg(short = 'v', default_value = "debug")]
    log_level: DaemonLevelFilter,
}

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

    log::set_logger(&LOGGER).unwrap();
    log::set_max_log_level(cli.log_level.into());

    Player::start()
}
