"""read_panel returns per-symbol {epoch_day: value} dicts for one feature — the crypto-panel read path."""
from __future__ import annotations

from fxhnt.adapters.warehouse.duckdb_feature_store import DuckDbFeatureStore
from fxhnt.application.warehouse_ingest import WarehouseIngest
from fxhnt.domain.warehouse.bar import BarRecord


def test_read_panel_groups_by_symbol_and_day(tmp_path) -> None:
    store = DuckDbFeatureStore(str(tmp_path / "wh.duckdb"))
    WarehouseIngest(store).ingest_bars("BTCUSDT", [BarRecord("BTCUSDT", 19000 * 86400, 100.0, 100.0, 100.0),
                                                   BarRecord("BTCUSDT", 19001 * 86400, 110.0, 110.0, 110.0)])
    WarehouseIngest(store).ingest_bars("ETHUSDT", [BarRecord("ETHUSDT", 19001 * 86400, 50.0, 50.0, 50.0)])
    panel = store.read_panel(["BTCUSDT", "ETHUSDT"], "close")
    assert panel["BTCUSDT"] == {19000: 100.0, 19001: 110.0}
    assert panel["ETHUSDT"] == {19001: 50.0}
    store.close()


def test_read_panel_empty_symbols(tmp_path) -> None:
    store = DuckDbFeatureStore(str(tmp_path / "wh.duckdb"))
    assert store.read_panel([], "close") == {}
    store.close()
