use std::fs;
use tempfile::TempDir;

#[test]
fn test_config_roundtrip() {
    let dir = TempDir::new().unwrap();
    let config_path = dir.path().join("config.toml");

    let content = r#"
[default]
api_secret = "test-secret-key"

[testnet]
api_secret = "testnet-key"
base_url = "https://api-testnet.backpack.exchange"
ws_url = "wss://ws-testnet.backpack.exchange"
"#;

    fs::write(&config_path, content).unwrap();
    let parsed: toml::Value = toml::from_str(content).unwrap();

    assert!(parsed.get("default").is_some());
    assert!(parsed.get("testnet").is_some());

    let default = parsed.get("default").unwrap();
    assert_eq!(
        default.get("api_secret").unwrap().as_str().unwrap(),
        "test-secret-key"
    );

    let testnet = parsed.get("testnet").unwrap();
    assert_eq!(
        testnet.get("base_url").unwrap().as_str().unwrap(),
        "https://api-testnet.backpack.exchange"
    );
}

#[test]
fn test_empty_config() {
    let content = "";
    let parsed: toml::Value = toml::from_str(content).unwrap();
    assert!(parsed.as_table().unwrap().is_empty());
}
