//! Tests for Kraken API error classification.

// We test the error module directly since it's pub
/// Mirror of KrakenError::from_api_errors logic for testing
fn classify_error(errors: Vec<String>) -> &'static str {
    if errors.is_empty() {
        return "unknown";
    }
    let msg = errors.join("; ");
    if msg.contains("EAPI:Rate limit") {
        "rate_limited"
    } else if msg.contains("EOrder:Insufficient funds") {
        "insufficient_funds"
    } else if msg.contains("EQuery:Unknown asset pair") {
        "unknown_pair"
    } else if msg.contains("EOrder:Unknown order") {
        "order_not_found"
    } else {
        "api_error"
    }
}

#[test]
fn classify_rate_limit() {
    let errors = vec!["EAPI:Rate limit exceeded".to_string()];
    assert_eq!(classify_error(errors), "rate_limited");
}

#[test]
fn classify_insufficient_funds() {
    let errors = vec!["EOrder:Insufficient funds".to_string()];
    assert_eq!(classify_error(errors), "insufficient_funds");
}

#[test]
fn classify_unknown_pair() {
    let errors = vec!["EQuery:Unknown asset pair".to_string()];
    assert_eq!(classify_error(errors), "unknown_pair");
}

#[test]
fn classify_unknown_order() {
    let errors = vec!["EOrder:Unknown order".to_string()];
    assert_eq!(classify_error(errors), "order_not_found");
}

#[test]
fn classify_generic_error() {
    let errors = vec!["EGeneral:Something went wrong".to_string()];
    assert_eq!(classify_error(errors), "api_error");
}

#[test]
fn classify_empty_errors() {
    assert_eq!(classify_error(vec![]), "unknown");
}

#[test]
fn classify_multiple_errors_joined() {
    let errors = vec![
        "EGeneral:First".to_string(),
        "EAPI:Rate limit exceeded".to_string(),
    ];
    assert_eq!(classify_error(errors), "rate_limited");
}
