
from src.fmatch.saas.operators.match_salesforce_account import (
    _normalize_domain,
    _normalize_company_name,
    _compute_match_score,
    ScoringBackend,
    AMBIGUITY_DELTA,
    SHORT_NAME_THRESHOLD,
)


def test_normalize_domain():
    assert _normalize_domain("https://www.cisco.com/products") == "cisco.com"
    assert _normalize_domain("www.ibm.com") == "ibm.com"
    assert _normalize_domain("microsoft.com") == "microsoft.com"
    assert _normalize_domain("") == ""


def test_normalize_company_name():
    assert _normalize_company_name("Cisco Systems, Inc.") == "cisco systems"
    assert _normalize_company_name("IBM Corp") == "ibm"
    assert _normalize_company_name("Microsoft Corporation") == "microsoft corporation"
    assert _normalize_company_name("") == ""


def test_compute_match_score_exact():
    score = _compute_match_score("Cisco Systems", "Cisco Systems", "cisco systems")
    assert score == 100


def test_compute_match_score_fuzzy():
    # Partial name match - "Cisco" vs "Cisco Systems, Inc." is a low-confidence match
    score = _compute_match_score("Cisco", "Cisco Systems, Inc.", "cisco")
    assert 50 <= score < 80  # Short name partial match should be below threshold

    # Better match - "Cisco Systems" vs "Cisco Systems, Inc." should score high
    score2 = _compute_match_score("Cisco Systems", "Cisco Systems, Inc.", "cisco systems")
    assert score2 >= 90  # Near-exact match after normalization


def test_scoring_backend_enum():
    """Test ScoringBackend enum values."""
    assert ScoringBackend.LOCAL.value == "local"
    assert ScoringBackend.ENGINE.value == "engine"


def test_ambiguity_constants():
    """Test tuning constants are reasonable."""
    assert AMBIGUITY_DELTA == 5  # Tight ambiguity window
    assert SHORT_NAME_THRESHOLD == 6  # Short names need domain or Engine
