use super::*;

#[test]
fn summarizes_save_slice_backed_fixtures() {
    let parity_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-parity-save-slice-fixture.json");
    let selective_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-selective-import-save-slice-fixture.json");
    let overlay_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-selective-import-overlay-fixture.json");
    let symbolic_overlay_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-symbolic-company-scope-overlay-fixture.json");
    let negative_company_scope_overlay_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-negative-company-scope-overlay-fixture.json");
    let deactivate_overlay_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-deactivate-company-overlay-fixture.json");
    let track_capacity_overlay_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-track-capacity-overlay-fixture.json");
    let mixed_overlay_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-mixed-company-descriptor-overlay-fixture.json");
    let named_locomotive_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
        "../../fixtures/runtime/packed-event-named-locomotive-availability-save-slice-fixture.json",
    );
    let missing_catalog_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
            "../../fixtures/runtime/packed-event-locomotive-availability-missing-catalog-save-slice-fixture.json",
        );
    let save_locomotive_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
        "../../fixtures/runtime/packed-event-locomotive-availability-save-slice-fixture.json",
    );
    let overlay_locomotive_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-locomotive-availability-overlay-fixture.json");
    let save_locomotive_cost_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-locomotive-cost-save-slice-fixture.json");
    let overlay_locomotive_cost_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-locomotive-cost-overlay-fixture.json");
    let scalar_band_parity_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
        "../../fixtures/runtime/packed-event-world-scalar-band-parity-save-slice-fixture.json",
    );
    let world_scalar_executable_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
        "../../fixtures/runtime/packed-event-world-scalar-executable-save-slice-fixture.json",
    );
    let world_scalar_override_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-world-scalar-override-save-slice-fixture.json");
    let runtime_variable_overlay_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-runtime-variable-overlay-fixture.json");
    let runtime_variable_condition_overlay_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join(
            "../../fixtures/runtime/packed-event-runtime-variable-condition-overlay-fixture.json",
        );
    let cargo_economics_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-cargo-economics-save-slice-fixture.json");
    let cargo_economics_parity_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-cargo-economics-parity-save-slice-fixture.json");
    let add_building_shell_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-add-building-shell-save-slice-fixture.json");
    let world_scalar_condition_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-world-scalar-condition-save-slice-fixture.json");
    let world_scalar_condition_parity_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
        "../../fixtures/runtime/packed-event-world-scalar-condition-parity-save-slice-fixture.json",
    );
    let cargo_catalog_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-cargo-catalog-save-slice-fixture.json");
    let chairman_cash_overlay_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-chairman-cash-overlay-fixture.json");
    let chairman_cash_save_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-chairman-cash-save-slice-fixture.json");
    let chairman_condition_true_save_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
        "../../fixtures/runtime/packed-event-chairman-condition-true-save-slice-fixture.json",
    );
    let chairman_human_cash_save_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-chairman-human-cash-save-slice-fixture.json");
    let deactivate_chairman_overlay_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-deactivate-chairman-overlay-fixture.json");
    let deactivate_chairman_save_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-deactivate-chairman-save-slice-fixture.json");
    let deactivate_chairman_ai_save_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-deactivate-chairman-ai-save-slice-fixture.json");
    let deactivate_company_save_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-deactivate-company-save-slice-fixture.json");
    let track_capacity_save_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-track-capacity-save-slice-fixture.json");
    let negative_company_scope_save_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-negative-company-scope-save-slice-fixture.json");
    let missing_chairman_context_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
        "../../fixtures/runtime/packed-event-chairman-missing-context-save-slice-fixture.json",
    );
    let chairman_scope_parity_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-chairman-scope-parity-save-slice-fixture.json");
    let chairman_condition_overlay_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-chairman-condition-overlay-fixture.json");
    let chairman_condition_save_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-chairman-condition-save-slice-fixture.json");
    let company_governance_condition_overlay_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join(
            "../../fixtures/runtime/packed-event-company-governance-condition-overlay-fixture.json",
        );
    let company_governance_condition_save_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
        "../../fixtures/runtime/packed-event-company-governance-condition-save-slice-fixture.json",
    );
    let selection_only_context_overlay_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-selection-only-context-overlay-fixture.json");
    let credit_rating_descriptor_save_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
        "../../fixtures/runtime/packed-event-credit-rating-descriptor-save-slice-fixture.json",
    );
    let stock_prices_shell_save_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-stock-prices-shell-save-slice-fixture.json");
    let game_won_shell_save_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-game-won-shell-save-slice-fixture.json");
    let merger_premium_shell_save_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-merger-premium-shell-save-slice-fixture.json");
    let set_human_control_shell_save_fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
        "../../fixtures/runtime/packed-event-set-human-control-shell-save-slice-fixture.json",
    );
    let investor_confidence_condition_save_fixture = PathBuf::from(env!(
            "CARGO_MANIFEST_DIR"
        ))
        .join(
            "../../fixtures/runtime/packed-event-investor-confidence-condition-save-slice-fixture.json",
        );
    let management_attitude_condition_save_fixture = PathBuf::from(env!(
            "CARGO_MANIFEST_DIR"
        ))
        .join(
            "../../fixtures/runtime/packed-event-management-attitude-condition-save-slice-fixture.json",
        );

    summarize_fixture(&parity_fixture).expect("save-slice-backed parity fixture should summarize");
    summarize_fixture(&selective_fixture)
        .expect("save-slice-backed selective-import fixture should summarize");
    summarize_fixture(&overlay_fixture)
        .expect("overlay-backed selective-import fixture should summarize");
    summarize_fixture(&symbolic_overlay_fixture)
        .expect("overlay-backed symbolic-target fixture should summarize");
    summarize_fixture(&negative_company_scope_overlay_fixture)
        .expect("overlay-backed negative-sentinel company-scope fixture should summarize");
    summarize_fixture(&deactivate_overlay_fixture)
        .expect("overlay-backed deactivate-company fixture should summarize");
    summarize_fixture(&track_capacity_overlay_fixture)
        .expect("overlay-backed track-capacity fixture should summarize");
    summarize_fixture(&mixed_overlay_fixture)
        .expect("overlay-backed mixed real-row fixture should summarize");
    summarize_fixture(&named_locomotive_fixture)
        .expect("save-slice-backed named locomotive availability fixture should summarize");
    summarize_fixture(&missing_catalog_fixture).expect(
        "save-slice-backed locomotive availability missing-catalog fixture should summarize",
    );
    summarize_fixture(&save_locomotive_fixture)
        .expect("save-slice-backed locomotive availability descriptor fixture should summarize");
    summarize_fixture(&overlay_locomotive_fixture)
        .expect("overlay-backed locomotive availability fixture should summarize");
    summarize_fixture(&save_locomotive_cost_fixture)
        .expect("save-slice-backed locomotive cost fixture should summarize");
    summarize_fixture(&overlay_locomotive_cost_fixture)
        .expect("overlay-backed locomotive cost fixture should summarize");
    summarize_fixture(&scalar_band_parity_fixture)
        .expect("save-slice-backed recovered scalar-band parity fixture should summarize");
    summarize_fixture(&world_scalar_executable_fixture)
        .expect("save-slice-backed executable world-scalar fixture should summarize");
    summarize_fixture(&world_scalar_override_fixture)
        .expect("save-slice-backed world-scalar override fixture should summarize");
    summarize_fixture(&runtime_variable_overlay_fixture)
        .expect("overlay-backed runtime-variable fixture should summarize");
    summarize_fixture(&runtime_variable_condition_overlay_fixture)
        .expect("overlay-backed runtime-variable condition fixture should summarize");
    summarize_fixture(&cargo_economics_fixture)
        .expect("save-slice-backed cargo-economics fixture should summarize");
    summarize_fixture(&cargo_economics_parity_fixture)
        .expect("save-slice-backed cargo-economics parity fixture should summarize");
    summarize_fixture(&add_building_shell_fixture)
        .expect("save-slice-backed add-building shell fixture should summarize");
    summarize_fixture(&world_scalar_condition_fixture)
        .expect("save-slice-backed executable world-scalar condition fixture should summarize");
    summarize_fixture(&world_scalar_condition_parity_fixture)
        .expect("save-slice-backed parity world-scalar condition fixture should summarize");
    summarize_fixture(&cargo_catalog_fixture)
        .expect("save-slice-backed cargo catalog fixture should summarize");
    summarize_fixture(&chairman_cash_overlay_fixture)
        .expect("overlay-backed chairman-cash fixture should summarize");
    summarize_fixture(&chairman_cash_save_fixture)
        .expect("save-slice-backed chairman-cash fixture should summarize");
    summarize_fixture(&chairman_condition_true_save_fixture)
        .expect("save-slice-backed condition-true chairman fixture should summarize");
    summarize_fixture(&chairman_human_cash_save_fixture)
        .expect("save-slice-backed human-chairman cash fixture should summarize");
    summarize_fixture(&deactivate_chairman_overlay_fixture)
        .expect("overlay-backed deactivate-chairman fixture should summarize");
    summarize_fixture(&deactivate_chairman_save_fixture)
        .expect("save-slice-backed deactivate-chairman fixture should summarize");
    summarize_fixture(&deactivate_chairman_ai_save_fixture)
        .expect("save-slice-backed AI-chairman deactivate fixture should summarize");
    summarize_fixture(&deactivate_company_save_fixture)
        .expect("save-slice-backed deactivate-company fixture should summarize");
    summarize_fixture(&track_capacity_save_fixture)
        .expect("save-slice-backed track-capacity fixture should summarize");
    summarize_fixture(&negative_company_scope_save_fixture)
        .expect("save-slice-backed negative-sentinel company-scope fixture should summarize");
    summarize_fixture(&missing_chairman_context_fixture)
        .expect("save-slice-backed chairman missing-context fixture should summarize");
    summarize_fixture(&chairman_scope_parity_fixture)
        .expect("save-slice-backed chairman scope parity fixture should summarize");
    summarize_fixture(&chairman_condition_overlay_fixture)
        .expect("overlay-backed chairman condition fixture should summarize");
    summarize_fixture(&chairman_condition_save_fixture)
        .expect("save-slice-backed chairman condition fixture should summarize");
    summarize_fixture(&company_governance_condition_overlay_fixture)
        .expect("overlay-backed company governance condition fixture should summarize");
    summarize_fixture(&company_governance_condition_save_fixture)
        .expect("save-slice-backed company governance condition fixture should summarize");
    summarize_fixture(&selection_only_context_overlay_fixture)
        .expect("overlay-backed selection-only save context fixture should summarize");
    summarize_fixture(&credit_rating_descriptor_save_fixture)
        .expect("save-slice-backed credit-rating descriptor fixture should summarize");
    summarize_fixture(&stock_prices_shell_save_fixture)
        .expect("save-slice-backed shell-owned stock-prices fixture should summarize");
    summarize_fixture(&game_won_shell_save_fixture)
        .expect("save-slice-backed shell-owned game-won fixture should summarize");
    summarize_fixture(&merger_premium_shell_save_fixture)
        .expect("save-slice-backed shell-owned merger-premium fixture should summarize");
    summarize_fixture(&set_human_control_shell_save_fixture)
        .expect("save-slice-backed shell-owned set-human-control fixture should summarize");
    summarize_fixture(&investor_confidence_condition_save_fixture)
        .expect("save-slice-backed investor-confidence condition fixture should summarize");
    summarize_fixture(&management_attitude_condition_save_fixture)
        .expect("save-slice-backed management-attitude condition fixture should summarize");
}

#[test]
fn diffs_runtime_states_between_save_slice_and_overlay_import() {
    let base = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-selective-import-save-slice.json");
    let overlay = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-selective-import-overlay.json");

    let left_state =
        load_normalized_runtime_state(&base).expect("save-slice-backed state should load");
    let right_state =
        load_normalized_runtime_state(&overlay).expect("overlay-backed state should load");
    let differences = diff_json_values(&left_state, &right_state);

    assert!(differences.iter().any(|entry| {
        entry.path == "$.companies[0].company_id"
            || entry.path == "$.packed_event_collection.imported_runtime_record_count"
            || entry.path == "$.packed_event_collection.records[1].import_outcome"
            || entry.path == "$.event_runtime_records[1].record_id"
    }));
}

#[test]
fn diffs_save_slice_backed_states_across_packed_event_boundaries() {
    let left_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-parity-save-slice.json");
    let right_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("../../fixtures/runtime/packed-event-selective-import-save-slice.json");

    let left_state = load_normalized_runtime_state(&left_path)
        .expect("left save-slice-backed state should load");
    let right_state = load_normalized_runtime_state(&right_path)
        .expect("right save-slice-backed state should load");
    let differences = diff_json_values(&left_state, &right_state);

    assert!(differences.iter().any(|entry| {
        entry.path == "$.packed_event_collection.imported_runtime_record_count"
            || entry.path == "$.packed_event_collection.records[0].decode_status"
    }));
}
