use clap::{Parser, Subcommand};

#[derive(Parser, Debug)]
#[command(name = "sshr", version, about = "SSH connectivity validator (russh)")]
pub struct Cli {
    #[command(subcommand)]
    pub command: Commands,
}

#[derive(Subcommand, Debug)]
pub enum Commands {
    Validate(ValidateArgs),
    Exec(ExecArgs),
    Shell(ShellArgs),
    Pty(PtyArgs),
}

#[derive(Parser, Debug, Clone)]
pub struct ValidateArgs {
    #[arg(long, env = "SSH_HOST")]
    pub host: String,

    #[arg(long, env = "SSH_PORT", default_value_t = 22)]
    pub port: u16,

    #[arg(long, env = "SSH_USER")]
    pub user: String,

    #[arg(long, env = "SSH_PASSWORD", hide_env_values = true)]
    pub password: Option<String>,

    #[arg(long, env = "SSH_KEY_PATH")]
    pub key_path: Option<String>,

    #[arg(long, env = "SSH_KEY_PASSPHRASE", hide_env_values = true)]
    pub key_passphrase: Option<String>,

    #[arg(long, env = "SSH_TIMEOUT_MS", default_value_t = 8000)]
    pub timeout_ms: u64,
}

#[derive(Parser, Debug, Clone)]
#[command(trailing_var_arg = true)]
pub struct ExecArgs {
    #[arg(long, env = "SSH_HOST")]
    pub host: String,

    #[arg(long, env = "SSH_PORT", default_value_t = 22)]
    pub port: u16,

    #[arg(long, env = "SSH_USER")]
    pub user: String,

    #[arg(long, env = "SSH_PASSWORD", hide_env_values = true)]
    pub password: Option<String>,

    #[arg(long, env = "SSH_KEY_PATH")]
    pub key_path: Option<String>,

    #[arg(long, env = "SSH_KEY_PASSPHRASE", hide_env_values = true)]
    pub key_passphrase: Option<String>,

    #[arg(long, env = "SSH_TIMEOUT_MS", default_value_t = 8000)]
    pub timeout_ms: u64,

    #[arg(required = true)]
    pub command: Vec<String>,
}

#[derive(Parser, Debug, Clone)]
pub struct ShellArgs {
    #[arg(long, env = "SSH_HOST")]
    pub host: String,

    #[arg(long, env = "SSH_PORT", default_value_t = 22)]
    pub port: u16,

    #[arg(long, env = "SSH_USER")]
    pub user: String,

    #[arg(long, env = "SSH_PASSWORD", hide_env_values = true)]
    pub password: Option<String>,

    #[arg(long, env = "SSH_KEY_PATH")]
    pub key_path: Option<String>,

    #[arg(long, env = "SSH_KEY_PASSPHRASE", hide_env_values = true)]
    pub key_passphrase: Option<String>,

    #[arg(long, env = "SSH_TIMEOUT_MS", default_value_t = 8000)]
    pub timeout_ms: u64,
}

#[derive(Parser, Debug, Clone)]
pub struct PtyArgs {
    #[arg(long, env = "SSH_HOST")]
    pub host: String,

    #[arg(long, env = "SSH_PORT", default_value_t = 22)]
    pub port: u16,

    #[arg(long, env = "SSH_USER")]
    pub user: String,

    #[arg(long, env = "SSH_PASSWORD", hide_env_values = true)]
    pub password: Option<String>,

    #[arg(long, env = "SSH_KEY_PATH")]
    pub key_path: Option<String>,

    #[arg(long, env = "SSH_KEY_PASSPHRASE", hide_env_values = true)]
    pub key_passphrase: Option<String>,

    #[arg(long, env = "SSH_TIMEOUT_MS", default_value_t = 8000)]
    pub timeout_ms: u64,
}
