//! Single live request against the real aviationweather.gov Data API, to
//! confirm the adapter decodes genuine structured data.
//!
//! `#[ignore]` so normal CI never reaches the network. Run on demand:
//!
//! ```text
//! cargo test -p aerocontext --test awc_live -- --ignored --nocapture
//! ```
//!
//! The request asks for a single product (`Metar`) over a bounding box,
//! so the adapter makes exactly ONE GET to `/metar`.
#![allow(clippy::expect_used, clippy::panic, missing_docs)]

use aerocontext::{AwcClient, AwcConfig, GeoPoint, ProductKind, WeatherBriefingProvider};
use aerocontext_core::{Area, AreaBriefingRequest};

#[tokio::test]
#[ignore = "hits the live aviationweather.gov API; run explicitly with --ignored"]
async fn single_live_metar_request_returns_structured_data() {
    let client = AwcClient::new(AwcConfig {
        user_agent: "aerocontext-awc-live-verify/0.1 (+contact: ops@example.com)".to_owned(),
        ..AwcConfig::default()
    })
    .expect("awc config");

    // A small box over the San Francisco Bay Area (KSFO/KOAK/KSJC) — a
    // region that always has current METARs.
    let request = AreaBriefingRequest {
        area: Area::BoundingBox {
            south_west: GeoPoint {
                lat: 37.2,
                lon: -122.6,
            },
            north_east: GeoPoint {
                lat: 38.0,
                lon: -121.7,
            },
        },
        products: vec![ProductKind::Metar],
        lookback_hours: None,
        departure_at: None,
    };

    let briefing = client
        .area_briefing(&request)
        .await
        .expect("live AWC request succeeds");

    assert_eq!(briefing.source, "awc");
    assert!(
        !briefing.products.is_empty(),
        "the Bay Area should always have at least one current METAR"
    );

    for product in &briefing.products {
        assert_eq!(product.kind, ProductKind::Metar);
        let station = product
            .location
            .as_deref()
            .expect("a decoded METAR carries its station id");
        assert!(!product.raw_text.is_empty(), "raw METAR text is present");
        assert!(
            product.raw_text.contains(station),
            "raw METAR {:?} should mention its station {station}",
            product.raw_text
        );
        assert!(
            product.issued_at.is_some(),
            "a decoded METAR carries an observation time"
        );
    }

    println!(
        "decoded {} live METAR(s); first: {}",
        briefing.products.len(),
        briefing.products[0].raw_text
    );
}
