mod common;

use common::mock_client;
use wiremock::matchers::{method, path, query_param};
use wiremock::{Mock, ResponseTemplate};

#[tokio::test]
async fn get_availability_sends_datastream_id_and_decodes() {
    let (server, client) = mock_client().await;
    Mock::given(method("GET"))
        .and(path("/v1/availability"))
        .and(query_param("datastream_id", "42"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
            "datastream": {
                "datastream_id": 42,
                "exchange": "binance",
                "instrument": "BTCUSDT",
                "stream_type": "trade",
                "wire_format": "json"
            },
            "ranges": [
                { "from": "1704067200000000000", "to": "1704153600000000000", "rows_estimate": 1000 }
            ],
            "updated_at": "2026-04-19T15:00:00Z"
        })))
        .mount(&server)
        .await;

    let a = client.availability().get(42).await.unwrap();
    assert_eq!(a.datastream.exchange, "binance");
    assert_eq!(a.ranges.len(), 1);
    assert_eq!(a.ranges[0].rows_estimate, 1000);
}
