from fxhnt.application.bybit_forward_track import _LEVERED_SLEEVE_SHAPE
from fxhnt.application.forward_models import BacktestSummary


def _fake_summary(strategy_id="bybit_4edge"):
    return BacktestSummary(strategy_id=strategy_id, as_of="2024-06-01", cagr=1.2, ann_vol=0.4,
                           sharpe=1.8, max_drawdown=-0.2, passed=True, dsr=0.9, is_sharpe=1.5,
                           oos_sharpe=1.4, pvalue=0.01)


def test_report_provider_dispatches_levered_kwargs(monkeypatch):
    import fxhnt.application.backtest_refs_report as mod
    calls = []

    def fake_engine(store, **kw):
        calls.append(kw)
        return _fake_summary(kw.get("strategy_id", "bybit_4edge"))

    monkeypatch.setattr(mod, "bybit_4edge_backtest_summary", fake_engine)
    monkeypatch.setattr(mod, "liquid_universe", lambda store, **kw: {"BTC", "ETH"})
    monkeypatch.setattr(mod, "load_unlock_events", lambda *a, **k: [])
    monkeypatch.setattr(mod, "_data_dir", lambda: "/tmp")

    sm = mod.report_backtest_summary("bybit_4edge_levered", store=object())
    assert sm is not None and sm.strategy_id == "bybit_4edge_levered"
    assert calls[-1]["leverage_shape"] == _LEVERED_SLEEVE_SHAPE
    assert calls[-1]["strategy_id"] == "bybit_4edge_levered"


def test_report_provider_positioning_single_sleeve(monkeypatch):
    import fxhnt.application.backtest_refs_report as mod
    calls = []
    monkeypatch.setattr(mod, "bybit_4edge_backtest_summary",
                        lambda store, **kw: (calls.append(kw), _fake_summary(kw.get("strategy_id")))[1])
    monkeypatch.setattr(mod, "liquid_universe", lambda store, **kw: {"BTC", "ETH"})
    monkeypatch.setattr(mod, "load_unlock_events", lambda *a, **k: [])
    monkeypatch.setattr(mod, "_data_dir", lambda: "/tmp")

    sm = mod.report_backtest_summary("positioning", store=object())
    assert sm.strategy_id == "positioning"
    assert calls[-1]["sleeves"] == ["positioning"]
