/// CLI argument definitions using clap v4.
///
/// The CLI supports two modes:
/// - Subcommand mode: `ph today`, `ph search`, `ph login`, etc.
/// - TUI mode (default): just `ph` launches the interactive terminal UI
///
/// Every command supports `--json` for machine-readable output.
use clap::{Parser, Subcommand};

/// Product Hunt CLI: browse launches, search products, and view post details from your terminal.
#[derive(Parser)]
#[command(
    name = "ph",
    about = "A blazing-fast CLI & TUI for Product Hunt",
    version,
    author,
    long_about = None
)]
pub struct Cli {
    /// Output results as JSON (for piping to scripts/agents)
    #[arg(long, global = true)]
    pub json: bool,

    /// Limit the number of results returned
    #[arg(short, long, global = true)]
    pub limit: Option<usize>,

    /// Enable verbose logging (can be used multiple times)
    #[arg(short, long, global = true, action = clap::ArgAction::Count)]
    pub verbose: u8,

    /// Subcommand to run (defaults to TUI mode)
    #[command(subcommand)]
    pub command: Option<Commands>,
}

/// Available CLI subcommands.
#[derive(Subcommand)]
pub enum Commands {
    /// Launch the interactive TUI (default when no subcommand is given)
    Tui,

    /// Authenticate with Product Hunt
    Login,

    /// Log out and remove stored token
    Logout,

    /// View today's top launches
    Today,

    /// Search products and makers
    Search {
        /// Search query string
        query: String,
    },

    /// View details for a specific post
    Post {
        /// Post ID (from Product Hunt URL or today's list)
        id: String,
    },

    /// Show configuration info and status
    Status,
}

impl Cli {
    /// Parse CLI arguments from std::env.
    pub fn parse_args() -> Self {
        Self::parse()
    }
}
