"""WarehouseSource.crypto_panel must equal RawFileSource.crypto_panel on the same data — proves the
SSOT swap is faithful (the A->B guarantee)."""
from __future__ import annotations

import numpy as np

from fxhnt.adapters.warehouse.duckdb_feature_store import DuckDbFeatureStore
from fxhnt.application.combined_book_source import RawFileSource, WarehouseSource
from fxhnt.application.silver_ingest_helpers import ingest_crypto_pit


def test_warehouse_panel_equals_rawfile_panel(tmp_path) -> None:
    cp = tmp_path / "crypto_pit"; cp.mkdir()
    np.savez(cp / "BTCUSDT.npz", day=np.array([19000, 19001, 19002]), close=np.array([100.0, 110.0, 105.0]))
    np.savez(cp / "ETHUSDT.npz", day=np.array([19001, 19002]), close=np.array([50.0, 55.0]))
    store = DuckDbFeatureStore(str(tmp_path / "wh.duckdb"))
    ingest_crypto_pit(store, str(cp))

    d_raw, s_raw, c_raw, r_raw = RawFileSource(str(tmp_path)).crypto_panel()
    d_wh, s_wh, c_wh, r_wh = WarehouseSource(store).crypto_panel()
    assert d_raw == d_wh and s_raw == s_wh
    assert np.allclose(c_raw, c_wh, equal_nan=True)
    assert np.allclose(r_raw, r_wh, equal_nan=True)
    store.close()
