"""display_names.py — the SINGLE internal-id -> human-name map every cockpit view uses (the plain-language
global constraint). Covers every STRATEGY_REGISTRY entry (never a raw id falls through to the template) plus
the sim-book override pills absorbed from app.py's former local `_SIM_BOOK_LABELS`, and the asset->plain-
description map used by the holdings table."""
from __future__ import annotations

from fxhnt.application.display_names import ASSET_DESCRIPTIONS, asset_description, display_name
from fxhnt.registry import STRATEGY_REGISTRY


def test_every_registry_strategy_has_a_display_name() -> None:
    for sid, entry in STRATEGY_REGISTRY.items():
        # multistrat is deliberately overridden with a friendlier pill label (see the next test) — every
        # other registry entry must resolve to its own registry `display_name`.
        if sid != "multistrat":
            assert display_name(sid) == entry["display_name"]
        assert display_name(sid) != sid   # never the bare raw id


def test_sim_book_overrides_are_plain_language() -> None:
    # The interim local pill labels from app.py's `_SIM_BOOK_LABELS` (Task 1), absorbed here.
    assert display_name("multistrat") == "ETF Portfolio"


def test_unknown_id_falls_back_to_itself_never_raises() -> None:
    assert display_name("not-a-real-strategy") == "not-a-real-strategy"


def test_asset_descriptions_cover_the_multistrat_instruments() -> None:
    assert ASSET_DESCRIPTIONS == {
        # US listings (modelled book / us-venue)
        "SPY": "US stocks", "IEF": "US Treasuries", "GLD": "Gold",
        "PDBC": "Commodities", "DBMF": "Managed futures",
        # UCITS listings actually held in the EU DU account (the multi-strat leg trades these)
        "CSPX": "US stocks", "CBU0": "US Treasuries", "IDTM": "US Treasuries",
        "IGLN": "Gold", "ICOM": "Commodities",
    }
    for sym, desc in ASSET_DESCRIPTIONS.items():
        assert asset_description(sym) == desc


def test_ucits_holdings_never_read_other() -> None:
    # The EU DU account holds the UCITS remap (KID/PRIIPs blocks the US ETFs), so the holdings table sees
    # CSPX/CBU0/IDTM/IGLN/ICOM — each MUST resolve to the same plain "what it is" as its US cousin, never the
    # generic "other" (the bug found verifying the IBKR detail page: real holdings reading "other").
    assert asset_description("CSPX") == "US stocks"
    assert asset_description("IGLN") == "Gold"
    assert asset_description("ICOM") == "Commodities"
    assert asset_description("CBU0") == "US Treasuries"
    assert asset_description("IDTM") == "US Treasuries"


def test_asset_description_unknown_symbol_falls_back_to_generic() -> None:
    # An unmapped symbol (e.g. a future vrp option contract) gets a plain generic word, never a blank or an
    # odd raw contract string — the symbol itself is still shown in its own column.
    assert asset_description("XYZ") == "other"
    assert asset_description("SPY  260130P00500000") == "other"
