use crate::{cdr, json, test, Version, Versioned as _};

#[test]
fn should_parse_v221_cdr_as_v211_with_unexpected_fields() {
    const JSON: &str = include_str!("../../test_data/v221/every_field_set/cdr.json");

    test::setup();

    let cdr = cdr::build(json::parse_object(JSON).unwrap(), Version::V211);

    assert_eq!(
        cdr.version(),
        Version::V211,
        "The v221 CDR was forced to be parsed as v211"
    );

    // Schema validation records an unexpected (or wrongly typed) field but does not descend into
    // it, so only the `v2.2.1`-only fields reachable from a `v2.1.1`-valid parent are reported.
    // For example, `$.cdr_location` and `$.cdr_token` appear but their children do not, and
    // `$.total_cost` is a type mismatch (object vs number) rather than an unexpected field so it is
    // not listed here at all.
    test::assert_unexpected_fields(
        &cdr,
        &[
            "$.cdr_location",
            "$.cdr_token",
            "$.charging_periods[0].tariff_id",
            "$.charging_periods[1].tariff_id",
            "$.country_code",
            "$.end_date_time",
            "$.party_id",
            "$.session_id",
            "$.tariffs[0].country_code",
            "$.tariffs[0].elements[0].price_components[0].vat",
            "$.tariffs[0].elements[0].restrictions.max_current",
            "$.tariffs[0].elements[0].restrictions.min_current",
            "$.tariffs[0].elements[0].restrictions.reservation",
            "$.tariffs[0].elements[1].price_components[0].vat",
            "$.tariffs[0].elements[2].price_components[0].vat",
            "$.tariffs[0].end_date_time",
            "$.tariffs[0].energy_mix.environ_impact[0].category",
            "$.tariffs[0].energy_mix.environ_impact[1].category",
            "$.tariffs[0].max_price",
            "$.tariffs[0].min_price",
            "$.tariffs[0].party_id",
            "$.tariffs[0].type",
            "$.total_energy_cost",
            "$.total_time_cost",
        ],
    );
}
