from fxhnt.application.paper_book import sleeve_daily_return
from fxhnt.domain.paper import Position


def _pos(sym, qty, entry):  # sleeve fixed; entry_price carries the PRIOR date's close
    return Position("s", sym, qty, entry, "2026-01-01")


def test_long_return_is_pnl_over_notional():
    prev = [_pos("A", 2.0, 100.0)]          # notional 200
    r = sleeve_daily_return(prev, {"A": 110.0})   # pnl = 2*(110-100)=20
    assert r == 20.0 / 200.0


def test_short_position_return():
    prev = [_pos("A", -2.0, 100.0)]         # notional |-2*100|=200
    r = sleeve_daily_return(prev, {"A": 90.0})    # pnl = -2*(90-100)=20
    assert r == 20.0 / 200.0


def test_unknown_symbol_contributes_zero():
    prev = [_pos("A", 2.0, 100.0), _pos("B", 1.0, 50.0)]   # notional 200+50=250
    r = sleeve_daily_return(prev, {"A": 110.0})            # B unknown -> 0 pnl; pnl=20
    assert r == 20.0 / 250.0


def test_no_prior_positions_returns_none():
    assert sleeve_daily_return([], {"A": 110.0}) is None


def test_zero_notional_returns_none():
    assert sleeve_daily_return([_pos("A", 0.0, 100.0)], {"A": 110.0}) is None
