//! The `voa config` subcommand.

use clap::Parser;
use voa_core::identifiers::{Context, Os, Purpose};

use crate::cli::OutputFormat;

/// The `voa config` subcommand.
#[derive(Debug, Parser)]
pub enum ConfigCommand {
    /// The `voa config list` subcommand.
    #[command(
        about = "List the origins of technology settings used by OSes and specific contexts."
    )]
    List(ConfigListCommand),

    /// The `voa config show` subcommand.
    #[command(about = "Show OS or context-level technology settings.")]
    Show(ConfigShowCommand),
}

#[derive(Debug, Parser)]
pub struct ConfigListCommand {
    #[arg(
        env = "VOA_CONFIG_LIST_OUTPUT_FORMAT",
        help = "The output format to use.",
        long,
        short,
        default_value_t = OutputFormat::default()
    )]
    pub output_format: OutputFormat,
}

#[derive(Debug, Parser)]
pub struct ConfigShowCommand {
    #[arg(env = "VOA_CONFIG_SHOW_OS", help = "The OS to search for.")]
    pub os: Os,

    #[arg(
        env = "VOA_CONFIG_SHOW_PURPOSE",
        help = "The purpose to search for.",
        long
    )]
    pub purpose: Option<Purpose>,

    #[arg(
        env = "VOA_CONFIG_SHOW_CONTEXT",
        help = "The context to search for.",
        long,
        long_help = r#"The context to search for.

If not specified, defaults to "default"."#,
        requires = "purpose"
    )]
    pub context: Option<Context>,

    #[arg(
        env = "VOA_CONFIG_SHOW_OUTPUT_FORMAT",
        help = "The output format to use.",
        long,
        short,
        default_value_t = OutputFormat::default()
    )]
    pub output_format: OutputFormat,
}
