"""Dispatch a sim book's honest-cost curve by its registry backtest.kind — bybit books read the precomputed
bybit_sleeve_ret table; recompute-replay books (multistrat, the IBKR paper strategies) read their own
precomputed curve. The sim NEVER recomputes an edge on the request path (both sources are nightly-precomputed:
bybit_sleeve_ret by `_persist_bybit_book`, the IBKR curve by `_persist_track_backtest_ref`)."""
from __future__ import annotations

from collections.abc import Callable

from fxhnt.application.backtest_refs import registry_backtest_kind

# The Backtest page's book pills, in render order. bybit_4edge/bybit_4edge_levered are the existing Bybit
# books (report-kind, precomputed bybit_sleeve_ret). multistrat is the IBKR paper strategy
# (recompute-replay-kind) added by Task 1/D1 — their curve is a precomputed per-day return series read the
# same cheap way (see `sim_returns_for`'s dispatch below).
SIM_BOOKS: tuple[str, ...] = ("bybit_4edge", "bybit_4edge_levered", "multistrat", "multistrat_levered")


def sim_returns_for(book: str, *, bybit_returns: Callable[[], dict[str, dict[int, float]]],
                    ibkr_curve: Callable[[str], dict[str, dict[int, float]]]
                    ) -> dict[str, dict[int, float]]:
    """`book`'s per-sleeve honest-cost return series — `{sleeve: {epoch_day: ret}}` — dispatched by the
    registry's `backtest.kind` for `book`: `recompute-replay` (multistrat) reads the precomputed IBKR
    curve via `ibkr_curve(book)`; everything else (the `report`-kind Bybit books) reads the precomputed
    `bybit_sleeve_ret` table via `bybit_returns()` — the existing path, unchanged."""
    kind = registry_backtest_kind(book)
    if kind == "recompute-replay":
        return ibkr_curve(book)
    return bybit_returns()   # report-kind bybit books (the existing path)
