"""The plain function behind combined_forward_nav materializes from the warehouse + books into a state
file (assets are invoked via their underlying function — no live Dagster instance needed)."""
from __future__ import annotations

import numpy as np

from fxhnt.adapters.orchestration.assets import build_combined_forward_nav
from fxhnt.adapters.warehouse.duckdb_feature_store import DuckDbFeatureStore
from fxhnt.application.combined_book_source import WarehouseSource
from fxhnt.application.silver_ingest_helpers import ingest_crypto_pit


def test_combined_forward_nav_materializes_from_warehouse(tmp_path) -> None:
    cp = tmp_path / "crypto_pit"; cp.mkdir()
    rng = np.random.default_rng(0)
    for sym in ("BTCUSDT", "ETHUSDT", "SOLUSDT", "XRPUSDT", "BNBUSDT", "ADAUSDT",
                "DOGEUSDT", "AVAXUSDT", "LINKUSDT", "LTCUSDT", "DOTUSDT", "TRXUSDT"):
        days = np.arange(19000, 19000 + 400, dtype=np.int64)
        close = np.cumprod(1.0 + rng.normal(0.0005, 0.02, 400)) * 100.0
        np.savez(cp / f"{sym}.npz", day=days, close=close)
    store = DuckDbFeatureStore(str(tmp_path / "wh.duckdb"))
    ingest_crypto_pit(store, str(cp))
    summary = build_combined_forward_nav(WarehouseSource(store), futures=[], state_path=str(tmp_path / "fwd.json"))
    assert summary.forward_days >= 0 and summary.inception is not None
    store.close()
