def test_region_score_no_districts_full_when_region_match():
    """자치구 미설정: 광역 일치 시 35점."""
    from app.matcher import _region_score
    profile = {"preferred_regions": ["서울"], "preferred_districts": {}}
    ann = {"region_name": "서울특별시", "district": None}
    score, _ = _region_score(profile, ann)
    assert score == 35


def test_region_score_no_districts_zero_when_region_mismatch():
    from app.matcher import _region_score
    profile = {"preferred_regions": ["서울"], "preferred_districts": {}}
    ann = {"region_name": "부산광역시", "district": None}
    score, _ = _region_score(profile, ann)
    assert score == 0


def test_region_score_s_tier_district():
    """광역 매칭 + S티어 자치구: 10 + 25 = 35."""
    from app.matcher import _region_score
    profile = {
        "preferred_regions": ["서울"],
        "preferred_districts": {"S": ["강남구"], "A": [], "B": [], "C": [], "D": []},
    }
    ann = {"region_name": "서울특별시", "district": "강남구"}
    score, _ = _region_score(profile, ann)
    assert score == 35


def test_region_score_a_tier_district():
    """광역 매칭 + A티어 자치구: 10 + 20 = 30."""
    from app.matcher import _region_score
    profile = {
        "preferred_regions": ["서울"],
        "preferred_districts": {"S": [], "A": ["송파구"], "B": [], "C": [], "D": []},
    }
    ann = {"region_name": "서울특별시", "district": "송파구"}
    score, _ = _region_score(profile, ann)
    assert score == 30


def test_region_score_d_tier_district():
    """광역 매칭 + D티어 자치구: 10 + 5 = 15."""
    from app.matcher import _region_score
    profile = {
        "preferred_regions": ["서울"],
        "preferred_districts": {"S": [], "A": [], "B": [], "C": [], "D": ["도봉구"]},
    }
    ann = {"region_name": "서울특별시", "district": "도봉구"}
    score, _ = _region_score(profile, ann)
    assert score == 15


def test_region_score_district_set_but_not_listed():
    """광역 매칭 + 자치구 5티어 어디에도 없음: 10점만."""
    from app.matcher import _region_score
    profile = {
        "preferred_regions": ["서울"],
        "preferred_districts": {"S": ["강남구"], "A": [], "B": [], "C": [], "D": []},
    }
    ann = {"region_name": "서울특별시", "district": "강서구"}
    score, _ = _region_score(profile, ann)
    assert score == 10


def test_eligibility_score_zero_when_empty():
    from app.matcher import _eligibility_score
    assert _eligibility_score([]) == 0


def test_eligibility_score_one_type_returns_15():
    from app.matcher import _eligibility_score
    assert _eligibility_score(["일반1순위"]) == 15


def test_eligibility_score_two_types_returns_20():
    from app.matcher import _eligibility_score
    assert _eligibility_score(["일반1순위", "특별-신혼부부"]) == 20


def test_eligibility_score_caps_at_25():
    from app.matcher import _eligibility_score
    assert _eligibility_score(["a", "b", "c", "d", "e"]) == 25


def test_region_score_b_tier_district():
    """광역 매칭 + B티어 자치구: 10 + 15 = 25."""
    from app.matcher import _region_score
    profile = {
        "preferred_regions": ["서울"],
        "preferred_districts": {"S": [], "A": [], "B": ["관악구"], "C": [], "D": []},
    }
    ann = {"region_name": "서울특별시", "district": "관악구"}
    score, _ = _region_score(profile, ann)
    assert score == 25


def test_region_score_c_tier_district():
    """광역 매칭 + C티어 자치구: 10 + 10 = 20."""
    from app.matcher import _region_score
    profile = {
        "preferred_regions": ["서울"],
        "preferred_districts": {"S": [], "A": [], "B": [], "C": ["은평구"], "D": []},
    }
    ann = {"region_name": "서울특별시", "district": "은평구"}
    score, _ = _region_score(profile, ann)
    assert score == 20
