import pytest

from app.services.enrichment.price_tiers import classify


BANDS = (5000, 20000)   # 33rd and 67th percentile, in minor units


@pytest.mark.parametrize("price,expected", [
    (100, "budget"),
    (4999, "budget"),
    (5000, "mid"),        # boundary belongs to the higher band
    (12000, "mid"),
    (20000, "premium"),   # boundary belongs to the higher band
    (500000, "premium"),
])
def test_classify(price, expected):
    assert classify(price, BANDS) == expected


def test_no_price_is_unclassified():
    assert classify(None, BANDS) is None


def test_no_bands_means_unclassified():
    # A catalog too small to have a distribution must not be given fake tiers.
    assert classify(1000, None) is None


def test_boundaries_are_documented_and_stable():
    # Pinned because a later phase filters on these and a silent shift would
    # move products between tiers without any code appearing to change.
    assert classify(4999, BANDS) == "budget"
    assert classify(5000, BANDS) == "mid"
    assert classify(19999, BANDS) == "mid"
    assert classify(20000, BANDS) == "premium"
