mod common;

use common::{authed_client, authenticate};

/// A fresh master wallet has no sub-accounts, but the endpoint must still
/// respond with a well-formed empty listing (not a 500 or auth error).
#[tokio::test]
#[ignore = "requires running API server"]
async fn fresh_wallet_has_no_sub_accounts() {
    let (token, _address, _signer) = authenticate().await;
    let authed = authed_client(&token);

    let resp = authed
        .list_sub_accounts_with_balances()
        .await
        .unwrap()
        .into_inner();

    let subs = resp.sub_accounts.unwrap_or_default();
    assert!(
        subs.is_empty(),
        "fresh wallet should have no sub-accounts, got {subs:?}"
    );
}

/// Looking up limits for a non-existent sub-account returns 403 or 404 —
/// never an unexpected response shape. This catches error-envelope drift.
#[tokio::test]
#[ignore = "requires running API server"]
async fn get_limits_for_unknown_sub_account_rejects() {
    let (token, _address, _signer) = authenticate().await;
    let authed = authed_client(&token);

    // Random UUID that no user has claimed.
    let phantom = uuid::Uuid::new_v4().to_string();
    let resp = authed.get_sub_account_limits(&phantom).await;

    let Err(err) = resp else {
        panic!("expected error looking up unknown sub-account, got Ok");
    };
    match err {
        monaco_sdk::Error::ErrorResponse(r) => {
            let status = r.status().as_u16();
            assert!(
                matches!(status, 400 | 401 | 403 | 404),
                "expected a 4xx error, got {status}"
            );
        }
        other => panic!("expected ErrorResponse(4xx), got {other:?}"),
    }
}
