use assert_cmd::Command;
use predicates::prelude::*;

#[allow(deprecated)]
fn bpx() -> Command {
    Command::cargo_bin("bpx").unwrap()
}

#[test]
fn test_help() {
    bpx()
        .arg("--help")
        .assert()
        .success()
        .stdout(predicate::str::contains(
            "Official CLI for Backpack Exchange",
        ));
}

#[test]
fn test_version() {
    bpx()
        .arg("--version")
        .assert()
        .success()
        .stdout(predicate::str::contains("bpx"));
}

#[test]
fn test_markets_help() {
    bpx()
        .args(["markets", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("Market data commands"));
}

#[test]
fn test_order_help() {
    bpx()
        .args(["order", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("Order management"));
}

#[test]
fn test_account_help() {
    bpx()
        .args(["account", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("Account information"));
}

#[test]
fn test_json_output_flag() {
    // Verify the -o json flag is accepted
    bpx()
        .args(["--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("table, json"));
}

// Integration tests that hit the live API
#[test]
#[ignore = "requires network"]
fn test_markets_list_live() {
    bpx()
        .args(["markets", "list"])
        .assert()
        .success()
        .stdout(predicate::str::contains("SYMBOL"));
}

#[test]
#[ignore = "requires network"]
fn test_markets_tickers_live() {
    bpx()
        .args(["markets", "tickers"])
        .assert()
        .success()
        .stdout(predicate::str::contains("SOL_USDC"));
}

#[test]
#[ignore = "requires network"]
fn test_markets_tickers_json_live() {
    bpx()
        .args(["markets", "tickers", "-o", "json"])
        .assert()
        .success()
        .stdout(predicate::str::contains("\"symbol\""));
}

#[test]
#[ignore = "requires network"]
fn test_markets_depth_live() {
    bpx()
        .args(["markets", "depth", "SOL_USDC", "--limit", "5"])
        .assert()
        .success()
        .stdout(predicate::str::contains("Order Book"));
}

#[test]
#[ignore = "requires network"]
fn test_status_live() {
    bpx()
        .args(["status"])
        .assert()
        .success()
        .stdout(predicate::str::contains("reachable"));
}
