from fmatch.saas.operators.clean_hidden_whitespace import clean_hidden_whitespace
from fmatch.saas.operators.normalize_boolean import normalize_boolean
from fmatch.saas.operators.normalize_fiscal_quarter import normalize_fiscal_quarter
from fmatch.saas.operators.normalize_percentage import normalize_percentage
from fmatch.saas.operators.validate_email_syntax import validate_email_syntax


def test_clean_hidden_whitespace():
    assert clean_hidden_whitespace("  John Doe\t")["value"] == "John Doe"
    assert clean_hidden_whitespace("Acme\u200B Corp")["value"] == "Acme Corp"
    assert clean_hidden_whitespace("Acme\u00A0 Corp")["value"] == "Acme Corp"


def test_normalize_boolean():
    assert normalize_boolean("Yes")["value"] is True
    assert normalize_boolean("inactive")["value"] is False
    assert normalize_boolean(1)["value"] is True
    assert normalize_boolean(0)["value"] is False
    assert normalize_boolean("maybe")["value"] == ""


def test_normalize_percentage():
    assert normalize_percentage("75%")["value"] == 0.75
    assert normalize_percentage("0.75")["value"] == 0.75
    assert normalize_percentage("75")["value"] == 0.75
    assert normalize_percentage("1.5")["value"] == 0.015
    assert normalize_percentage(".75")["value"] == 0.75
    assert normalize_percentage("")["value"] == ""


def test_normalize_fiscal_quarter():
    assert normalize_fiscal_quarter("Q3-FY26")["value"] == "FY26-Q3"
    assert normalize_fiscal_quarter("FY2026 Q3")["value"] == "FY26-Q3"
    assert normalize_fiscal_quarter("3Q26")["value"] == "FY26-Q3"
    assert normalize_fiscal_quarter("2026Q3")["value"] == "FY26-Q3"
    assert normalize_fiscal_quarter("")["value"] == ""


def test_validate_email_syntax():
    assert validate_email_syntax("john@example.com")["value"] == [True, ""]
    assert validate_email_syntax("john@@acme.com")["value"] == [False, "multiple_at"]
    assert validate_email_syntax("john@acme")["value"] == [False, "missing_tld"]
    assert validate_email_syntax("john@.com")["value"] == [False, "invalid_domain"]
    assert validate_email_syntax("")["value"] == [False, "empty"]
