from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def read(path: str) -> str:
    return (ROOT / path).read_text(encoding="utf-8")


def test_fiscal_enrichment_ignores_public_domains_for_internal_identity_matching():
    source = read("app/fiscal_enrichment_service.py")
    assert "raw_domain = normalize_domain" in source
    assert "domain = \"\" if is_public_email_domain(raw_domain) else raw_domain" in source
    assert "not is_public_email_domain(email_domain)" in source
    assert "email_identity_company_internal_domain" in source


def test_task_detail_warns_that_public_email_domains_are_not_identity_evidence():
    source = read("app/admin_ui/pages/tasks.py")
    assert "PUBLIC_CONTACT_EMAIL_DOMAINS" in source
    assert '"sapo.pt"' in source
    assert "def _task_public_domain_identity_context" in source
    assert "Domínio público não confirma identidade" in source
    assert "_task_public_domain_identity_warning_html(task)" in source
