"""TASK 1 (2026-07-16 UCITS re-base plan): UCITS map exposes a Yahoo LSE volume ticker + per-line
half-spread, and the equity_execution_regime flag defaults to "ucits" (retail EU) with an env override
to "us" (post-MiFID-II professional). See docs/superpowers/plans/2026-07-16-equity-ucits-rebase.md."""
from fxhnt.config import AllocationSettings, Settings, UcitsListing


def test_ucits_listing_defaults_yahoo_ticker_from_ticker_when_empty():
    listing = UcitsListing(ticker="CSPX", isin="IE00B5BMR087", half_spread_bps=1.5)
    assert listing.yahoo_ticker == "CSPX.L"


def test_ucits_listing_explicit_yahoo_ticker_not_overridden():
    listing = UcitsListing(ticker="DBMF", isin="LU2951555585", yahoo_ticker="DBMF.L", half_spread_bps=30.0)
    assert listing.yahoo_ticker == "DBMF.L"


def test_ucits_map_yahoo_tickers():
    settings = Settings()
    m = settings.ucits.map
    assert m["SPY"].yahoo_ticker == "CSPX.L"
    assert m["IEF"].yahoo_ticker == "CBU0.L"
    assert m["GLD"].yahoo_ticker == "IGLN.L"
    assert m["PDBC"].yahoo_ticker == "ICOM.L"
    assert m["DBMF"].yahoo_ticker == "DBMF.L"


def test_ucits_map_half_spread_bps():
    settings = Settings()
    m = settings.ucits.map
    assert m["SPY"].half_spread_bps == 1.5     # CSPX
    assert m["IEF"].half_spread_bps == 2.0     # CBU0
    assert m["GLD"].half_spread_bps == 2.0     # IGLN
    assert m["PDBC"].half_spread_bps == 8.0    # ICOM
    assert m["DBMF"].half_spread_bps == 30.0   # DBMF


def test_equity_execution_regime_defaults_ucits():
    assert AllocationSettings().equity_execution_regime == "ucits"


def test_equity_execution_regime_env_override_us(monkeypatch):
    monkeypatch.setenv("FXHNT_ALLOCATION_EQUITY_EXECUTION_REGIME", "us")
    assert AllocationSettings().equity_execution_regime == "us"
