import pytest

from ArWikiCats.format_bots.pf_keys import change_key_mappings_replacements, change_key_secondary_replacements


class TestChangeKeyMappingsReplacements:
    test_data = {
        "category:american television series based on non-american television series": "category:american television series basedon non-american television series",
        "category:australian television series based on non-australian television series": "category:australian television series basedon non-australian television series",
        "category:austrian television series based on non-austrian television series": "category:austrian television series basedon non-austrian television series",
        "category:belgian television series based on non-belgian television series": "category:belgian television series basedon non-belgian television series",
        "category:brazilian television series based on non-brazilian television series": "category:brazilian television series basedon non-brazilian television series",
        "category:british television series based on non-british television series": "category:british television series basedon non-british television series",
        "category:bulgarian television series based on non-bulgarian television series": "category:bulgarian television series basedon non-bulgarian television series",
        "comedy- test": "comedy  test",
        "something comedy- something": "something comedy  something",
        # Test cases for each key in CHANGE_KEY_MAPPINGS
        " labor test": " labour test",
        "labor test": "labour test",
        "something labor something": "something labour something",
        "labor": "labour",
        " labor ": " labour ",
        "war of test": "war-of test",
        "something war of something": "something war-of something",
        "war of yemen": "war-of yemen",
        "category:players in test": "category:playerss in test",
        "players in test": "playerss in test",
        "something players in something": "something playerss in something",
        "something players in": "something playerss in",
        "players in": "playerss in",
        "tennis test": "tennis test",
        "something tennis something": "something tennis something",
        "tennis": "tennis",
        "accidents and incidents test": "accidents-and-incidents test",
        "something accidents and incidents something": "something accidents-and-incidents something",
        "accidents and incidents": "accidents-and-incidents",
        "adaptations of works test": "adaptations-of-works test",
        "something adaptations of works something": "something adaptations-of-works something",
        "adaptations of works": "adaptations-of-works",
        "africa cup of nations test": "africa cup-of-nations test",
        "something africa cup of nations something": "something africa cup-of-nations something",
        "africa cup of nations": "africa cup-of-nations",
        "african american test": "africanamerican test",
        "something african american something": "something africanamerican something",
        "african american": "africanamerican",
        "african-american test": "africanamerican test",
        "something african-american something": "something africanamerican something",
        "african-american": "africanamerican",
        "ancient greek test": "ancient-greek test",
        "something ancient greek something": "something ancient-greek something",
        "ancient greek": "ancient-greek",
        "ancient macedonian test": "ancient-macedonian test",
        "something ancient macedonian something": "something ancient-macedonian something",
        "ancient macedonian": "ancient-macedonian",
        "ancient roman test": "ancient-roman test",
        "something ancient roman something": "something ancient-roman something",
        "ancient roman": "ancient-roman",
        "architecture schools test": "architecture-schools test",
        "something architecture schools something": "something architecture-schools something",
        "architecture schools": "architecture-schools",
        "association football afc test": "association-football afc test",
        "something association football afc something": "something association-football afc something",
        "association football afc": "association-football afc",
        "athletes (track and field) test": "track and field athletes test",
        "something athletes (track and field) something": "something track and field athletes something",
        "athletes (track and field)": "track and field athletes",
        "bodies of water test": "bodies-of-water test",
        "something bodies of water something": "something bodies-of-water something",
        "bodies of water": "bodies-of-water",
        "british hong kong test": "british-hong-kong test",
        "something british hong kong something": "something british-hong-kong something",
        "british hong kong": "british-hong-kong",
        "built by test": "built-by test",
        "something built by something": "something built-by something",
        "built by": "built-by",
        "built in test": "built-in test",
        "something built in something": "something built-in something",
        "built in": "built-in",
        "by car bomb test": "by-car-bomb test",
        "something by car bomb something": "something by-car-bomb something",
        "by car bomb": "by-car-bomb",
        "by firearm in test": "by-firearm-in test",
        "something by firearm in something": "something by-firearm-in something",
        "by firearm in": "by-firearm-in",
        "canadian football test": "canadian-football test",
        "something canadian football something": "something canadian-football something",
        "canadian football": "canadian-football",
        "canton of test": "canton-of test",
        "something canton of something": "something canton-of something",
        "canton of": "canton-of",
        "caribbean people test": "caribbeans people test",
        "something caribbean people something": "something caribbeans people something",
        "caribbean people": "caribbeans people",
        "child soldiers test": "child-soldiers test",
        "something child soldiers something": "something child-soldiers something",
        "child soldiers": "child-soldiers",
        "city of liverpool f.c. test": "city-of-liverpool f.c. test",
        "something city of liverpool f.c. something": "something city-of-liverpool f.c. something",
        "city of liverpool f.c.": "city-of-liverpool f.c.",
        "city of london test": "city-of-london test",
        "something city of london something": "something city-of-london something",
        "city of london": "city-of-london",
        "colony of test": "colony-of test",
        "something colony of something": "something colony-of something",
        "colony of": "colony-of",
        "comedy-": "comedy",
        "county of test": "county-of test",
        "something county of something": "something county-of something",
        "county of": "county-of",
        "crown of test": "crown-of test",
        "something crown of something": "something crown-of something",
        "crown of": "crown-of",
        "domain of test": "domain-of test",
        "something domain of something": "something domain-of something",
        "domain of": "domain-of",
        "duchy of test": "duchy-of test",
        "something duchy of something": "something duchy-of something",
        "duchy of": "duchy-of",
        "early modern test": "early-modern test",
        "something early modern something": "something early-modern something",
        "early modern": "early-modern",
        "emirate of test": "emirate-of test",
        "something emirate of something": "something emirate-of something",
        "emirate of": "emirate-of",
        "executions by test": "executions in test",
        "something executions by something": "something executions in something",
        "executions by": "executions in",
        "football (soccer) test": "football test",
        "something football (soccer) something": "something football something",
        "football (soccer)": "football",
        "for member of parliament test": "for member-of-parliament test",
        "something for member of parliament something": "something for member-of-parliament something",
        "for member of parliament": "for member-of-parliament",
        "future elections test": "future-elections test",
        "something future elections something": "something future-elections something",
        "future elections": "future-elections",
        "general elections test": "general-elections test",
        "something general elections something": "something general-elections something",
        "general elections": "general-elections",
        "elections, ": "elections ",
        "elections,  test": "elections  test",
        "something elections,  something": "something elections  something",
        "governance of policing test": "governance policing test",
        "something governance of policing something": "something governance policing something",
        "governance of policing": "governance policing",
        "harrow on hill test": "harrow-on-hill test",
        "something harrow on hill something": "something harrow-on-hill something",
        "harrow on hill": "harrow-on-hill",
        "health care test": "healthcare test",
        "something health care something": "something healthcare something",
        "health care": "healthcare",
        "imprisoned in test": "imprisoned-in test",
        "something imprisoned in something": "something imprisoned-in something",
        "imprisoned in": "imprisoned-in",
        "in northern ireland test": "in northern-ireland test",
        "something in northern ireland something": "something in northern-ireland something",
        "in northern ireland": "in northern-ireland",
        "in sport in test": "in-sport-in test",
        "something in sport in something": "something in-sport-in something",
        "in sport in": "in-sport-in",
        "in sports in test": "in-sports-in test",
        "something in sports in something": "something in-sports-in something",
        "in sports in": "in-sports-in",
        "isle of test": "isle-of test",
        "something isle of something": "something isle-of something",
        "isle of": "isle-of",
        "killed in action test": "killed-in-action test",
        "something killed in action something": "something killed-in-action something",
        "killed in action": "killed-in-action",
        "kingdom of test": "kingdom-of test",
        "something kingdom of something": "something kingdom-of something",
        "kingdom of": "kingdom-of",
        "labour and social security test": "labour-and-social security test",
        "something labour and social security something": "something labour-and-social security something",
        "labour and social security": "labour-and-social security",
        "launched by test": "launched-by test",
        "something launched by something": "something launched-by something",
        "launched by": "launched-by",
        "launched in test": "launched-in test",
        "something launched in something": "something launched-in something",
        "launched in": "launched-in",
        "local elections test": "local-elections test",
        "something local elections something": "something local-elections something",
        "local elections": "local-elections",
        "manufactured by test": "manufactured-by test",
        "something manufactured by something": "something manufactured-by something",
        "manufactured by": "manufactured-by",
        "manufactured in test": "manufactured-in test",
        "something manufactured in something": "something manufactured-in something",
        "manufactured in": "manufactured-in",
        "march of test": "march-of test",
        "something march of something": "something march-of something",
        "march of": "march-of",
        "margraviate of test": "margraviate-of test",
        "something margraviate of something": "something margraviate-of something",
        "margraviate of": "margraviate-of",
        "medallists test": "medalists test",
        "something medallists something": "something medalists something",
        "medallists": "medalists",
        "military equipment test": "military-equipment test",
        "something military equipment something": "something military-equipment something",
        "military equipment": "military-equipment",
        "military terminology test": "military-terminology test",
        "something military terminology something": "something military-terminology something",
        "military terminology": "military-terminology",
        "ministers for test": "ministers-for test",
        "something ministers for something": "something ministers-for something",
        "ministers for": "ministers-for",
        "murderers of children test": "murderersofchildren test",
        "something murderers of children something": "something murderersofchildren something",
        "murderers of children": "murderersofchildren",
        "national register of historic places test": "national-register-of-historic-places test",
        "something national register of historic places something": "something national-register-of-historic-places something",
        "national register of historic places": "national-register-of-historic-places",
        "presidential elections test": "presidential-elections test",
        "something presidential elections something": "something presidential-elections something",
        "presidential elections": "presidential-elections",
        "presidential primaries test": "presidential-primaries test",
        "something presidential primaries something": "something presidential-primaries something",
        "presidential primaries": "presidential-primaries",
        "prisoners of conscience test": "prisoners-of-conscience test",
        "something prisoners of conscience something": "something prisoners-of-conscience something",
        "prisoners of conscience": "prisoners-of-conscience",
        "protectorate of test": "protectorate-of test",
        "something protectorate of something": "something protectorate-of something",
        "protectorate of": "protectorate-of",
        "publishers (people) test": "publisherspeople test",
        "something publishers (people) something": "something publisherspeople something",
        "publishers (people)": "publisherspeople",
        "realm of test": "realm-of test",
        "something realm of something": "something realm-of something",
        "realm of": "realm-of",
        "refusing to convert to christianity test": "refusing-to-convert-to-christianity test",
        "something refusing to convert to christianity something": "something refusing-to-convert-to-christianity something",
        "refusing to convert to christianity": "refusing-to-convert-to-christianity",
        "refusing to convert to islam test": "refusing-to-convert-to-islam test",
        "something refusing to convert to islam something": "something refusing-to-convert-to-islam something",
        "refusing to convert to islam": "refusing-to-convert-to-islam",
        "republic of test": "republic-of test",
        "something republic of something": "something republic-of something",
        "republic of": "republic-of",
        "saudi arabian test": "saudiarabian test",
        "something saudi arabian something": "something saudiarabian something",
        "saudi arabian": "saudiarabian",
        "scholars of islam test": "scholars-of-islam test",
        "something scholars of islam something": "something scholars-of-islam something",
        "scholars of islam": "scholars-of-islam",
        "shot dead by law enforcement officers test": "shot dead-by-law enforcement officers test",
        "something shot dead by law enforcement officers something": "something shot dead-by-law enforcement officers something",
        "shot dead by law enforcement officers": "shot dead-by-law enforcement officers",
        "sport ministers test": "sport-ministers test",
        "something sport ministers something": "something sport-ministers something",
        "sport ministers": "sport-ministers",
        "sports culture test": "sports-culture test",
        "something sports culture something": "something sports-culture something",
        "sports culture": "sports-culture",
        "sports media test": "sports-media test",
        "something sports media something": "something sports-media something",
        "sports media": "sports-media",
        "sports ministers test": "sports-ministers test",
        "something sports ministers something": "something sports-ministers something",
        "sports ministers": "sports-ministers",
        "sportspeople test": "sports-people test",
        "something sportspeople something": "something sports-people something",
        "sportspeople": "sports-people",
        "states of test": "states-of test",
        "something states of something": "something states-of something",
        "states of": "states-of",
        "television films debuts test": "television films-debuts test",
        "something television films debuts something": "something television films-debuts something",
        "television films debuts": "television films-debuts",
        "television films endings test": "television films-endings test",
        "something television films endings something": "something television films-endings something",
        "television films endings": "television films-endings",
        "television miniseries debuts test": "television miniseries-debuts test",
        "something television miniseries debuts something": "something television miniseries-debuts something",
        "television miniseries debuts": "television miniseries-debuts",
        "television miniseries endings test": "television miniseries-endings test",
        "something television miniseries endings something": "something television miniseries-endings something",
        "television miniseries endings": "television miniseries-endings",
        "television seasons test": "television-seasons test",
        "something television seasons something": "something television-seasons something",
        "television seasons": "television-seasons",
        "television series debuts test": "television series-debuts test",
        "something television series debuts something": "something television series-debuts something",
        "television series debuts": "television series-debuts",
        "television series endings test": "television series-endings test",
        "something television series endings something": "something television series-endings something",
        "television series endings": "television series-endings",
        "transferred from test": "transferred-from test",
        "something transferred from something": "something transferred-from something",
        "transferred from": "transferred-from",
        "united states house of representatives test": "united states house-of-representatives test",
        "something united states house of representatives something": "something united states house-of-representatives something",
        "united states house of representatives": "united states house-of-representatives",
        "university of reading test": "university-of-reading test",
        "something university of reading something": "something university-of-reading something",
        "university of reading": "university-of-reading",
        "university of science and technology test": "university-of-science and technology test",
        "something university of science and technology something": "something university-of-science and technology something",
        "university of science and technology": "university-of-science and technology",
        "university of technology test": "university-of-technology test",
        "something university of technology something": "something university-of-technology something",
        "university of technology": "university-of-technology",
        "us open tennis test": "us open tennis test",
        "something us open tennis something": "something us open tennis something",
        "us open tennis": "us open tennis",
        "viceroyalty of test": "viceroyalty-of test",
        "something viceroyalty of something": "something viceroyalty-of something",
        "viceroyalty of": "viceroyalty-of",
        "west coast of united states test": "west coast-of-united states test",
        "something west coast of united states something": "something west coast-of-united states something",
        "west coast of united states": "west coast-of-united states",
        "world championships in athletics test": "world championships-in-athletics test",
        "something world championships in athletics something": "something world championships-in-athletics something",
        "world championships in athletics": "world championships-in-athletics",
        "world war i test": "world-war-i test",
        "something world war i something": "something world-war-i something",
        "world war i": "world-war-i",
        "world war ii test": "world-war-ii test",
        "something world war ii something": "something world-war-ii something",
        "world war ii": "world-war-ii",
        "’ test": "' test",
        "something ’ something": "something ' something",
        "’": "'",
        "defunct privately held companies test": "defunct-privately held-companies test",
        "something defunct privately held companies something": "something defunct-privately held-companies something",
        "defunct privately held companies": "defunct-privately held-companies",
        " - men's tournament test": " mens tournament test",
        " - men's tournament": " mens tournament",
        " - women's tournament test": " womens tournament test",
        " - women's tournament": " womens tournament",
        " – men's tournament test": " mens tournament test",
        " – men's tournament": " mens tournament",
        " – women's tournament test": " womens tournament test",
        " – women's tournament": " womens tournament",
        "category: - men's tournament test": "category: mens tournament test",
        "category: - women's tournament test": "category: womens tournament test",
        "something - men's tournament something": "something mens tournament something",
        "something - men's tournament": "something mens tournament",
        "something - women's tournament something": "something womens tournament something",
        "something - women's tournament": "something womens tournament",
        "something – men's tournament something": "something mens tournament something",
        "something – women's tournament something": "something womens tournament something",
    }

    @pytest.mark.parametrize("input_text,expected", test_data.items(), ids=test_data.keys())
    def test_change_key_mappings_replacements(self, input_text: str, expected: str) -> None:
        result = change_key_mappings_replacements(input_text)
        assert result.strip() == expected.strip()


class TestChangeKeySecondaryReplacements:
    tests_data_secondary = {
        "category:schools for deaf in new york (state)": "category:schools for-deaf in new york (state)",
        "category:royal national college for blind": "category:royal national college for-blind",
        "category:royal national college for blind by city": "category:royal national college for-blind by city",
        "category:marathi films remade in other languages": "category:marathi films remade-in other languages",
    }

    @pytest.mark.parametrize("input_text,expected", tests_data_secondary.items(), ids=tests_data_secondary.keys())
    def test_change_key_secondary_mappings_replacements(self, input_text: str, expected: str) -> None:
        result = change_key_secondary_replacements(input_text)
        assert result.strip() == expected.strip()

    mens_events = {
        "Category:2010s events at Games": "Category:2010s events in Games",
        "Category:men’s events at 2010 Commonwealth Games": "Category:mens-events in 2010 Commonwealth Games",
        "Category:men's events at Commonwealth Games": "Category:mens-events in Commonwealth Games",
        "Category:2020 men's events Games": "Category:2020 mens-events Games",
    }

    @pytest.mark.parametrize("input_text,expected", mens_events.items(), ids=mens_events.keys())
    def test_mens_events(self, input_text: str, expected: str) -> None:
        result = change_key_secondary_replacements(input_text)
        assert result.strip() == expected.strip()

    womens_footballers = {
        "Category:Brazilian expatriate women's footballers": "Category:Brazilian expatriate female footballers",
        "Category:Women's footballers in Kazakhstan by club": "Category:Women's footballers in Kazakhstan by club",
        "Category:2020 Women's footballers by club": "Category:2020 Women's footballers by club",
    }

    @pytest.mark.parametrize("input_text,expected", womens_footballers.items(), ids=womens_footballers.keys())
    def test_womens_footballers(self, input_text: str, expected: str) -> None:
        result = change_key_secondary_replacements(input_text)
        assert result.strip() == expected.strip()
