#![allow(
    clippy::unwrap_used,
    clippy::expect_used,
    clippy::panic,
    clippy::needless_raw_string_hashes,
    clippy::duration_suboptimal_units,
    clippy::branches_sharing_code,
    clippy::used_underscore_binding,
    clippy::single_char_pattern,
    clippy::ignore_without_reason,
    clippy::cloned_ref_to_slice_refs,
    clippy::doc_overindented_list_items,
    clippy::match_wildcard_for_single_variants,
    clippy::ignored_unit_patterns,
    clippy::needless_collect,
    clippy::unnecessary_map_or,
    clippy::manual_flatten,
    clippy::manual_strip,
    clippy::future_not_send,
    clippy::unnested_or_patterns,
    clippy::no_effect_underscore_binding,
    clippy::literal_string_with_formatting_args
)]

use std::process::Command;
use std::str;

#[test]
#[ignore]
fn test_cli_help() {
    let output = Command::new("./target/release/ggen")
        .arg("--help")
        .output()
        .expect("Failed to execute command");

    assert!(output.status.success());
    let stdout = str::from_utf8(&output.stdout).unwrap();
    assert!(stdout.contains("ggen"));
    // Modern noun-verb commands:
    assert!(stdout.contains("project"));
    assert!(stdout.contains("workflow"));
}

// COMMENTED OUT: Legacy hazard command test
// #[test]
// fn test_hazard_command() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "hazard"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     // Test passes if command runs without panicking
//     // The actual output depends on the ggen_core::commands::hazard implementation
//     assert!(output.status.code().is_some());
// }

#[test]
fn test_error_command() {
    let output = Command::new(env!("CARGO_BIN_EXE_ggen"))
        .arg("error")
        .output()
        .expect("Failed to execute command");

    // Test passes if command runs without panicking
    // The actual output depends on the ggen_core::commands::simulate_error implementation
    assert!(output.status.code().is_some());
}

#[test]
fn test_config_command() {
    let output = Command::new(env!("CARGO_BIN_EXE_ggen"))
        .arg("config")
        .output()
        .expect("Failed to execute command");

    // Test passes if command runs without panicking
    // The actual output depends on the ggen_core::commands::config implementation
    assert!(output.status.code().is_some());
}

// #[test] // COMMENTED OUT: Command line completion code
// fn test_completion_bash() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "shell", "completion", "generate", "--shell", "bash"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(output.status.success());
//     let stdout = str::from_utf8(&output.stdout).unwrap();
//     // Bash completion should contain function definitions
//     assert!(stdout.contains("_ggen"));
// }

// #[test] // COMMENTED OUT: Command line completion code
// fn test_completion_zsh() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "shell", "completion", "generate", "--shell", "zsh"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(output.status.success());
//     let stdout = str::from_utf8(&output.stdout).unwrap();
//     // Zsh completion should contain completion definitions
//     assert!(stdout.contains("compdef"));
// }

// #[test] // COMMENTED OUT: Command line completion code
// fn test_completion_fish() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "shell", "completion", "generate", "--shell", "fish"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(output.status.success());
//     let stdout = str::from_utf8(&output.stdout).unwrap();
//     // Fish completion should contain complete commands
//     assert!(stdout.contains("complete"));
// }

#[test]
fn test_invalid_command() {
    let output = Command::new(env!("CARGO_BIN_EXE_ggen"))
        .arg("invalid-command")
        .output()
        .expect("Failed to execute command");

    assert!(!output.status.success());
    let stderr = str::from_utf8(&output.stderr).unwrap();
    assert!(stderr.contains("error"));
}

// COMMENTED OUT: Legacy hazard command test with config flag
// #[test]
// fn test_config_flag() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "--config", "/nonexistent/path", "hazard"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     // Should handle config file not found gracefully
//     assert!(output.status.code().is_some());
// }

// COMMENTED OUT: Legacy hazard command test with debug flag
// #[test]
// fn test_debug_flag() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "--debug", "true", "hazard"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     // Should handle debug flag without issues
//     assert!(output.status.code().is_some());
// }

// Integration tests for noun-verb command structure
// COMMENTED OUT: audit command not available in current CLI
// #[test]
// fn test_audit_hazard_help() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "audit", "hazard", "--help"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(output.status.success());
//     let stdout = str::from_utf8(&output.stdout).unwrap();
//     assert!(stdout.contains("hazardous patterns"));
//     assert!(stdout.contains("scan"));
//     assert!(stdout.contains("list"));
//     assert!(stdout.contains("check"));
// }

// COMMENTED OUT: audit command not available in current CLI
// #[test]
// fn test_audit_security_help() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "audit", "security", "--help"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(output.status.success());
//     let stdout = str::from_utf8(&output.stdout).unwrap();
//     assert!(stdout.contains("security"));
//     assert!(stdout.contains("vulnerability"));
// }

// COMMENTED OUT: audit command not available in current CLI
// #[test]
// fn test_audit_performance_help() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "audit", "performance", "--help"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(output.status.success());
//     let stdout = str::from_utf8(&output.stdout).unwrap();
//     assert!(stdout.contains("performance"));
//     assert!(stdout.contains("benchmark"));
// }

// COMMENTED OUT: ci command not available in current CLI
// #[test]
// fn test_ci_pages_help() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "ci", "pages", "--help"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(output.status.success());
//     let stdout = str::from_utf8(&output.stdout).unwrap();
//     assert!(stdout.contains("GitHub Pages"));
//     assert!(stdout.contains("deploy"));
//     assert!(stdout.contains("status"));
//     assert!(stdout.contains("logs"));
//     assert!(stdout.contains("compare"));
// }

// COMMENTED OUT: ci command not available in current CLI
// #[test]
// fn test_ci_workflow_help() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "ci", "workflow", "--help"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(output.status.success());
//     let stdout = str::from_utf8(&output.stdout).unwrap();
//     assert!(stdout.contains("workflow"));
//     assert!(stdout.contains("list"));
//     assert!(stdout.contains("status"));
//     assert!(stdout.contains("logs"));
//     assert!(stdout.contains("cancel"));
// }

// COMMENTED OUT: ci command not available in current CLI
// #[test]
// fn test_ci_trigger_help() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "ci", "trigger", "--help"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(output.status.success());
//     let stdout = str::from_utf8(&output.stdout).unwrap();
//     assert!(stdout.contains("trigger"));
//     assert!(stdout.contains("workflow"));
// }

// #[test] // COMMENTED OUT: Command line completion code
// fn test_shell_completion_help() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "shell", "completion", "--help"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(output.status.success());
//     let stdout = str::from_utf8(&output.stdout).unwrap();
//     assert!(stdout.contains("completion"));
//     assert!(stdout.contains("generate"));
//     assert!(stdout.contains("install"));
//     assert!(stdout.contains("list"));
// }

// COMMENTED OUT: shell command not available in current CLI
// #[test]
// fn test_shell_init_help() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "shell", "init", "--help"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(output.status.success());
//     let stdout = str::from_utf8(&output.stdout).unwrap();
//     assert!(stdout.contains("init"));
//     assert!(stdout.contains("shell"));
//     assert!(stdout.contains("project"));
//     assert!(stdout.contains("dev"));
// }

// COMMENTED OUT: audit command not available in current CLI
// #[test]
// fn test_audit_hazard_scan_help() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "audit", "hazard", "scan", "--help"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(output.status.success());
//     let stdout = str::from_utf8(&output.stdout).unwrap();
//     assert!(stdout.contains("scan"));
//     assert!(stdout.contains("path"));
//     assert!(stdout.contains("json"));
//     assert!(stdout.contains("verbose"));
//     assert!(stdout.contains("fix"));
// }

// COMMENTED OUT: ci command not available in current CLI
// #[test]
// fn test_ci_pages_deploy_help() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "ci", "pages", "deploy", "--help"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(output.status.success());
//     let stdout = str::from_utf8(&output.stdout).unwrap();
//     assert!(stdout.contains("deploy"));
//     assert!(stdout.contains("force"));
//     assert!(stdout.contains("wait"));
//     assert!(stdout.contains("branch"));
// }

// #[test] // COMMENTED OUT: Command line completion code
// fn test_shell_completion_generate_help() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "shell", "completion", "generate", "--help"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(output.status.success());
//     let stdout = str::from_utf8(&output.stdout).unwrap();
//     assert!(stdout.contains("generate"));
//     assert!(stdout.contains("shell"));
//     assert!(stdout.contains("output"));
// }

// COMMENTED OUT: shell command not available in current CLI
// #[test]
// fn test_shell_init_shell_help() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "shell", "init", "shell", "--help"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(output.status.success());
//     let stdout = str::from_utf8(&output.stdout).unwrap();
//     assert!(stdout.contains("shell"));
//     assert!(stdout.contains("config"));
//     assert!(stdout.contains("force"));
// }

// Test error cases for noun-verb commands
// COMMENTED OUT: audit command not available in current CLI
// #[test]
// fn test_audit_invalid_subcommand() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "audit", "invalid"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(!output.status.success());
//     let stderr = str::from_utf8(&output.stderr).unwrap();
//     assert!(stderr.contains("error"));
// }

// COMMENTED OUT: ci command not available in current CLI
// #[test]
// fn test_ci_invalid_subcommand() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "ci", "invalid"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(!output.status.success());
//     let stderr = str::from_utf8(&output.stderr).unwrap();
//     assert!(stderr.contains("error"));
// }

// COMMENTED OUT: shell command not available in current CLI
// #[test]
// fn test_shell_invalid_subcommand() {
//     let output = Command::new("cargo")
//         .args(&["run", "--", "shell", "invalid"])
//         .current_dir(".")
//         .output()
//         .expect("Failed to execute command");
//
//     assert!(!output.status.success());
//     let stderr = str::from_utf8(&output.stderr).unwrap();
//     assert!(stderr.contains("error"));
// }
