use akira_billing::devices::device_limit_from_error;
use akira_billing::error::Error;

#[test]
fn parses_device_limit_error() {
    let body = serde_json::json!({
        "code": "device_limit_reached",
        "message": "limit",
        "slots_limit": 3,
        "slots_used": 3,
        "devices": [{ "id": "d1", "device_type": "desktop", "activated_at": "x" }],
    });
    let err = Error::Api {
        status: 409,
        code: "device_limit_reached".into(),
        body: Some(body),
    };

    let info = device_limit_from_error(&err).expect("device limit info");
    assert_eq!(info.slots_limit, 3);
    assert_eq!(info.slots_used, 3);
    assert_eq!(info.devices.len(), 1);
    assert_eq!(info.devices[0].id, "d1");
}

#[test]
fn ignores_unrelated_errors() {
    let err = Error::Api {
        status: 500,
        code: "server_error".into(),
        body: None,
    };
    assert!(device_limit_from_error(&err).is_none());
}
