import pytest

from fmatch.saas.operators import (
    extract_domain_root,
    is_business_email,
    split_fullname,
    state_name_to_code,
)


PARITY_CASES = {
    "split_fullname": [
        ("John Smith", ["John", "Smith"]),
        ("Smith, John", ["John", "Smith"]),
        ("John Smith Jr", ["John", "Smith"]),
        ("Mary Jane Watson", ["Mary", "Watson"]),
    ],
    "state_name_to_code": [
        ("California", "CA"),
        ("Ontario", "ON"),
        ("Queensland", "QLD"),
    ],
    "extract_domain_root": [
        ("george.abad@lmhosp.org", "lmhosp.org"),
        ("https://www.example.co.uk/page", "example.co.uk"),
    ],
    "is_business_email": [
        ("corp@nationwidechildrens.org", True),
        ("personal@gmail.com", False),
    ],
}


@pytest.mark.parametrize("value,expected", PARITY_CASES["split_fullname"])
def test_split_fullname_parity(value, expected):
    assert split_fullname(value)["value"] == expected


@pytest.mark.parametrize("value,expected", PARITY_CASES["state_name_to_code"])
def test_state_name_to_code_parity(value, expected):
    assert state_name_to_code(value)["value"] == expected


@pytest.mark.parametrize("value,expected", PARITY_CASES["extract_domain_root"])
def test_extract_domain_root_parity(value, expected):
    assert extract_domain_root(value)["value"] == expected


@pytest.mark.parametrize("value,expected", PARITY_CASES["is_business_email"])
def test_is_business_email_parity(value, expected):
    assert is_business_email(value)["value"] is expected
