import datetime as dt
from fxhnt.adapters.persistence.paper_repo import PaperRepo

def _repo():
    r = PaperRepo("sqlite://"); r.migrate(); return r

def test_nav_equity_before_and_latest():
    r = _repo(); at = dt.datetime(2026, 1, 2, tzinfo=dt.UTC)
    assert r.nav_equity_before("2026-01-01") is None      # nothing yet
    assert r.latest_nav_equity() is None
    r.upsert_nav("2026-01-01", capital=100000.0, realized=0.0, unrealized=0.0, equity=100000.0, at=at)
    r.upsert_nav("2026-01-02", capital=100000.0, realized=0.0, unrealized=5000.0, equity=105000.0, at=at)
    assert r.nav_equity_before("2026-01-02") == 100000.0  # strictly-prior
    assert r.nav_equity_before("2026-01-01") is None
    assert r.nav_equity_before("2026-01-03") == 105000.0
    assert r.latest_nav_equity() == 105000.0
