import pytest

from apps.web.routers.backtest import (
    _natural_sort_key,
    get_form4_capture_presets,
    get_idle_alpha_presets,
    get_ownership_capture_presets,
    get_parking_presets,
    get_risk_off_alpha_presets,
)
from libs.backtest.domain import (
    FORM4_CAPTURE_SLEEVE_PRESETS,
    IDLE_ALPHA_SLEEVE_PRESETS,
    OWNERSHIP_CAPTURE_SLEEVE_PRESETS,
    PARKING_PRESETS,
    RISK_OFF_ALPHA_SLEEVE_PRESETS,
)


@pytest.mark.parametrize(
    ("endpoint", "available_presets", "group_label"),
    [
        (get_parking_presets, PARKING_PRESETS, "Parking Presets"),
        (get_idle_alpha_presets, IDLE_ALPHA_SLEEVE_PRESETS, "Idle Alpha Sleeve Presets"),
        (get_form4_capture_presets, FORM4_CAPTURE_SLEEVE_PRESETS, "Form 4 Sleeve Presets"),
        (get_ownership_capture_presets, OWNERSHIP_CAPTURE_SLEEVE_PRESETS, "Ownership Sleeve Presets"),
        (get_risk_off_alpha_presets, RISK_OFF_ALPHA_SLEEVE_PRESETS, "Risk-Off Alpha Sleeve Presets"),
    ],
)
def test_preset_endpoints_return_all_available_presets(
    endpoint,
    available_presets,
    group_label: str,
) -> None:
    payload = endpoint()
    expected = sorted(available_presets.keys(), key=_natural_sort_key)

    assert payload["presets"] == expected
    assert payload["groups"] == {group_label: expected}
