"""The brand fold key, ahead of migration #3's brands table.

Measured 2026-09-03: 52 launch-scale duplicate product groups, most of them
one brand spelled several ways across shops ("Moët & Chandon" at one airport,
"MOET CHANDON" at another). The fold must join those and nothing else.
"""

import pytest

from app.services.normalize import brand_key


class TestFolds:
    @pytest.mark.parametrize("spelling", ["Moët & Chandon", "MOET ET CHANDON", "moet-chandon", "Moet and Chandon", "Moët&Chandon"])
    def test_every_spelling_of_one_house_agrees(self, spelling):
        assert brand_key(spelling) == "moet chandon"

    @pytest.mark.parametrize(("spelling", "key"), [
        ("Tanqueray Gin", "tanqueray"),
        ("Tanqueray Distillery", "tanqueray"),
        ("The Macallan", "macallan"),
        ("Glenfiddich Whisky", "glenfiddich"),
        ("Hendrick's", "hendricks"),
        ("Yves Saint Laurent Beauty", "yves saint laurent"),
        ("Dior Parfums", "dior"),
    ])
    def test_trailing_category_and_corporate_words_are_not_the_brand(self, spelling, key):
        assert brand_key(spelling) == key


class TestDoesNotOverFold:
    def test_a_brand_that_is_a_category_word_survives(self):
        """"Gin Mare" is a brand; stripping from the end never touches its head."""
        assert brand_key("Gin Mare") == "gin mare"
        assert brand_key("Gin") == "gin"

    def test_spaces_still_separate_different_houses(self):
        assert brand_key("Glen Moray") != brand_key("Glenmorangie")
        assert brand_key("Glen Grant") != brand_key("Glengrant")

    def test_no_brand_is_empty_not_none(self):
        assert brand_key(None) == "" and brand_key("") == ""
