import importlib

mcp = importlib.import_module("contas_mcp.servers.contas_mcp_server.main")


def test_multiple_named_subjects_use_unique_catalog_resolution(monkeypatch):
    catalog = [{"name": "Netflix Mensal"}, {"name": "HBO Max Standard"}, {"name": "TIM Fashion Mensal"}]
    monkeypatch.setattr(mcp, "_vas_domain_policy_from_invoice_detail", lambda name, args: ("cancelar_vas_avulso", "avulso"))
    monkeypatch.setattr(mcp, "_invoice_detail_msisdn", lambda detail, name: "11999999999")
    items = mcp._resolve_multiple_vas_subjects("cancela Netflix e HBO", catalog, {"msisdn": "11999999999"})
    assert [x["name"] for x in items] == ["Netflix Mensal", "HBO Max Standard"]


def test_generic_todos_does_not_expand_mass_cancellation(monkeypatch):
    catalog = [{"name": "Netflix Mensal"}, {"name": "TIM Fashion Mensal"}]
    monkeypatch.setattr(mcp, "_vas_domain_policy_from_invoice_detail", lambda name, args: ("cancelar_vas_avulso", "avulso"))
    assert mcp._resolve_multiple_vas_subjects("cancela todos", catalog, {}) == []


def test_explicit_all_avulsos_filters_non_avulso(monkeypatch):
    catalog = [{"name": "VAS A"}, {"name": "Netflix"}]
    monkeypatch.setattr(mcp, "_vas_domain_policy_from_invoice_detail", lambda name, args: ("cancelar_vas_avulso", "avulso") if name == "VAS A" else ("vas_estrategico", "estrategico"))
    monkeypatch.setattr(mcp, "_invoice_detail_msisdn", lambda detail, name: "11999999999")
    items = mcp._resolve_multiple_vas_subjects("cancele todos os VAS avulsos", catalog, {"msisdn": "11999999999"})
    assert [x["name"] for x in items] == ["VAS A"]
