mod handler;
mod lyrics;
mod lyrics_api;
mod metadata;

use clap::Parser;
use env_logger::{Builder, Env};
use handler::*;
use std::path::PathBuf;

#[derive(Parser, Debug)]
#[command(name = "lscribe")]
#[command(
    version,
    about = "CLI tool for download lyrics for you're local library"
)]
pub struct Args {
    /// Output lyrics to console after download
    #[arg(short, long)]
    output: bool,

    /// Write .lrc or .txt file
    #[arg(short, long)]
    write_lrc_file: bool,

    /// Fetch word-level karaoke format of lyrics from musixmatch.com
    #[arg(short, long, conflicts_with = "plain_only")]
    enhanced: bool,

    /// Fetch only plain text (not synced) lyrics from genius.com
    #[arg(short, long, conflicts_with = "enhanced")]
    plain_only: bool,

    /// Remove empty lines from synced lyrics
    #[arg(
        short = 'R',
        long,
        conflicts_with = "plain_only",
        conflicts_with = "enhanced"
    )]
    remove_empty_lines: bool,

    /// Recursive directory scan
    #[arg(short, long)]
    recursive: bool,

    /// Path to file or directory
    #[arg(required = true)]
    path: PathBuf,
}

impl Args {
    pub fn output(&self) -> bool {
        self.output
    }

    pub fn enhanced(&self) -> bool {
        self.enhanced
    }

    pub fn write_as_file(&self) -> bool {
        self.write_lrc_file
    }
}

fn main() {
    let env = Env::new().filter_or("RUST_LOG", "info");
    Builder::from_env(env).init();
    let args = Args::parse();
    open_path(&args.path, &args);
}
