import pytest

from d2rlootreader.item_parser import ItemParser

ITEMS = [
    {
        "quality": "Base",
        "name": "Boneweave",
        "base": "Boneweave",
        "slot": "Body",
        "tier": "Elite",
        "requirements": {"strength": 158, "level": 47},
        "stats": {"defense": [576]},
        "affixes": [
            ("+#% Enhanced Defense", [14]),
            ("Socketed (#)", [4]),
        ],
        "tooltip": [
            "Superior Boneweave",
            "Defense: 576",
            "Durability: 26 of 45",
            "Required Strength: 158",
            "Required Level: 47",
            "+14% Enhanced Defense",
            "Socketed (4)",
        ],
    },
    {
        "quality": "Magic",
        "name": "of the Squid",
        "base": "Heavy Belt",
        "slot": "Belt",
        "tier": "Normal",
        "requirements": {"strength": 45, "level": 30},
        "stats": {"defense": [6]},
        "affixes": [
            ("+# to Life", [70]),
        ],
        "tooltip": [
            "Heavy Belt of the Squid",
            "Defense: 6",
            "Belt Size: +8 Slots",
            "Durability: 18 of 18",
            "Required Strength: 45",
            "Required Level: 30",
            "+70 to Life",
        ],
    },
    {
        "quality": "Magic",
        "name": "of Blight",
        "base": "Blade",
        "slot": "Dagger",
        "tier": "Normal",
        "requirements": {"strength": 35, "dexterity": 51, "level": 3},
        "stats": {"one_hand_damage": [4, 15]},
        "affixes": [
            ("+# Poison Damage over # Seconds", [7, 3]),
        ],
        "tooltip": [
            "Blade of Blight",
            "One-hand Damage: 4 to 15",
            "Durability: 24 of 24",
            "Required Dexterity: 51",
            "Required Strength: 35",
            "Required Level: 3",
            "Dagger Class - Very Fast Attack Speed",
            "+7 Poison Damage over 3 Seconds",
        ],
    },
    {
        "quality": "Magic",
        "name": "Deadly of Quality",
        "base": "Scimitar",
        "slot": "Sword",
        "tier": "Normal",
        "requirements": {"dexterity": 21, "level": 5},
        "stats": {"one_hand_damage": [2, 9]},
        "affixes": [
            ("+#% Enhanced Damage", [25]),
            ("+# to Maximum Damage", [2]),
        ],
        "tooltip": [
            "Deadly Scimitar of Quality",
            "One-hand Damage: 2 to 9",
            "Durability: 22 of 22",
            "Required Dexterity: 21",
            "Required Level: S",
            "Sword Class - Very Fast Attack Speed",
            "+25% Enhanced Damage",
            "+2 to Maximum Damage",
        ],
    },
    {
        "quality": "Magic",
        "name": "Deadly",
        "base": "Broad Sword",
        "slot": "Sword",
        "tier": "Normal",
        "requirements": {"strength": 48, "level": 5},
        "stats": {"one_hand_damage": [8, 17]},
        "affixes": [
            ("+#% Enhanced Damage", [26]),
        ],
        "tooltip": [
            "Deadly Broad Sword",
            "One-hand Damage: 8 to 17",
            "Durability: 32 of 32",
            "Required Strength: 48",
            "Required Level: S",
            "Sword Class - Fast Attack Speed",
            "+26% Enhanced Damage",
        ],
    },
    {
        "quality": "Magic",
        "name": "Crimson of Remedy",
        "base": "Leather Armor",
        "slot": "Body",
        "tier": "Normal",
        "requirements": {"strength": 15, "level": 5},
        "stats": {"defense": [16]},
        "affixes": [
            ("Fire Resist +#%", [5]),
            ("Poison Length Reduced by #%", [25]),
        ],
        "tooltip": [
            "Crimson Leather Armor of Remedy",
            "Defense: 16",
            "Durability: 24 of 24",
            "Required Strength: 15",
            "Required Level: 5",
            "Fire Resist +5%",
            "Poison Length Reduced by 25%",
        ],
    },
    {
        "quality": "Magic",
        "name": "Lapis",
        "base": "Tower Shield",
        "slot": "Shield",
        "tier": "Normal",
        "requirements": {"strength": 75, "level": 9},
        "stats": {"defense": [24]},
        "affixes": [
            ("Cold Resist +#%", [19]),
        ],
        "tooltip": [
            "Lapis Tower Shield",
            "Defense: 24",
            "Chance to Block: 491:",
            "Durability: 60 of 60",
            "Required Strength: 75",
            "Required Level: 9",
            "Cold Resist +19%",
        ],
    },
    {
        "quality": "Magic",
        "name": "Great Wyrm's of the Apprentice",
        "base": "Ring",
        "slot": "Ring",
        "tier": "Normal",
        "requirements": {"level": 29},
        "stats": {},
        "affixes": [
            ("+#% Faster Cast Rate", [10]),
            ("+# to Mana", [78]),
        ],
        "tooltip": [
            "Great Wyrm's Ring of the Apprentice",
            "Required Level: 29",
            "+10% Faster Cast Rate",
            "+78 to Mana",
        ],
    },
    {
        "quality": "Magic",
        "name": "Shogukusha's of Sustenance",
        "base": "Grand Charm",
        "slot": "Inventory",
        "tier": "Normal",
        "requirements": {"level": 42},
        "stats": {},
        "affixes": [
            ("+# to Martial Arts (Assassin only)", [1]),
            ("+# to Life", [23]),
        ],
        "tooltip": [
            "Shogukusha's Grand Charm of Sustenance",
            "Keep in Inventory to Gain Bonus",
            "Required Level: 42",
            "+1 to Martial arts (Assassin Only)",
            "+23 to Life",
        ],
    },
    {
        "quality": "Rare",
        "name": "Havoc knuckle",
        "base": "Sharkskin Gloves",
        "slot": "Gloves",
        "tier": "Exceptional",
        "requirements": {"strength": 20, "level": 35},
        "stats": {"defense": [74]},
        "affixes": [
            ("+# to Martial Arts (Assassin only)", [2]),
            ("+#% Increased Attack Speed", [20]),
            ("+#% Enhanced Defense", [85]),
            ("Lightning Resist +#%", [14]),
            ("Repairs # durability in # seconds", [1, 20]),
        ],
        "tooltip": [
            "Havoc Knuckle",
            "Sharkskin Gloves",
            "Defense: 74",
            "Durability: 14 of 14",
            "Required Strength: 20",
            "Required Level: 35",
            "+2 to Martial Aarts (Assassin Only)",
            "+20% Increased Attack Speed",
            "+85% Enhanced Defense",
            "Lightning Resist +14%",
            "Repairs 1 durability in 20 Seconds",
        ],
    },
    {
        "quality": "Rare",
        "name": "Stone circlet",
        "base": "Circlet",
        "slot": "Helm",
        "tier": "Normal",
        "requirements": {"level": 67},
        "stats": {"defense": [29]},
        "affixes": [
            ("+# to Assassin Skill Levels", [2]),
            ("+#% Faster Cast Rate", [20]),
            ("+# to Attack Rating", [87]),
            ("Poison Length Reduced by #%", [50]),
        ],
        "tooltip": [
            "Stone Circlet",
            "Circlet",
            "Defense: 29",
            "Durability: 35 of 35",
            "Required Level: 67",
            "+2 to Assassin Skill Levels",
            "+20% Faster Cast Rate",
            "+87 to Attack Rating",
            "Poison Length Reduced by 50%",
        ],
    },
    {
        "quality": "Rare",
        "name": "Entropy gyre",
        "base": "Ring",
        "slot": "Ring",
        "tier": "Normal",
        "requirements": {"level": 68},
        "stats": {},
        "affixes": [
            ("+#% Faster Cast Rate", [10]),
            ("#% Mana stolen per hit", [5]),
            ("#% Life stolen per hit", [2]),
            ("+# to Strength", [4]),
            ("+# to Life", [20]),
            ("+# to Mana", [45]),
            ("+# Maximum Stamina", [14]),
        ],
        "tooltip": [
            "Entropy Gyre",
            "Ring",
            "Required Level: 68",
            "+10% Faster Cast Rate",
            "5% Mana stolen per Hit",
            "2% Life stolen per hit",
            "+4 to Strength",
            "+20 to Life",
            "+45 to Mana",
            "+14 Maximum Stamina",
        ],
    },
    {
        "quality": "Runeword",
        "name": "Fortitude",
        "base": "Great Hauberk",
        "slot": "Body",
        "tier": "Elite",
        "requirements": {"strength": 118, "level": 59},
        "stats": {"defense": [1596]},
        "affixes": [
            ("#% Chance to cast level # [Skill] when struck", [20, 15, "Chilling Armor"]),
            ("+#% Faster Cast Rate", [25]),
            ("+#% Enhanced Damage", [300]),
            ("+#% Enhanced Defense", [215]),
            ("+# Defense", [15]),
            ("+# to Life (Based on Character Level)", [101]),
            ("Replenish Life +#", [7]),
            ("+#% to Maximum Lightning Resist", [5]),
            ("All Resistances +#", [29]),
            ("Damage Reduced by #", [7]),
            ("+#% Damage Taken Goes To Mana", [12]),
            ("+# to Light Radius", [1]),
            ("Increase Maximum Durability #%", [13]),
            ("Socketed (#)", [4]),
        ],
        "tooltip": [
            "Fortitode",
            "Storm's Great Hauberk",
            "‘Elsoldollo'",
            "Defense: 1596",
            "Durability: 51 of 56",
            "Required Strength: 118",
            "Reouired Level: 59",
            "20% Chance to Cast Level 15 Chilling Armor When Struck",
            "+25% Faster Cast Rate",
            "+300% Enhanced Damage",
            "+215% Enhanced Defense",
            "+15 Defense",
            "+101 to Life (Based on Character Level)",
            "Replenish Life +7",
            "+5% to Maximum Lightning Resist",
            "All Resistances +29",
            "Damage Reduced by 7",
            "+12% Damage Taken Goes To Mana",
            "+1 to Light Radius",
            "Increase Maximum Durability 13%",
            "Socketed (4)",
        ],
    },
    {
        "quality": "Runeword",
        "name": "Call to Arms",
        "base": "Divine Scepter",
        "slot": "Scepter",
        "tier": "Exceptional",
        "requirements": {"strength": 103, "level": 57},
        "stats": {"one_hand_damage": [61, 146]},
        "affixes": [
            ("+# to All Skills", [1]),
            ("+#% Increased Attack Speed", [40]),
            ("+#% Enhanced Damage", [285]),
            ("+# to Attack Rating", [2]),
            ("Adds #-# Fire Damage", [5, 30]),
            ("#% Life stolen per hit", [7]),
            ("+# to [Skill] (Paladin only)", [1, "Sanctuary"]),
            ("+# to [Skill]", [6, "Battle Command"]),
            ("+# to [Skill]", [2, "Battle Orders"]),
            ("+# to [Skill]", [1, "Battle Cry"]),
            ("Prevent Monster Heal", []),
            ("Replenish Life +#", [12]),
            ("#% Better Chance of Getting Magic Items", [30]),
            ("+#% Damage to Undead", [50]),
            ("Socketed (#)", [5]),
        ],
        "tooltip": [
            "Call to Arms",
            "Divine Scepter",
            "Amnralmalistohm'",
            "one-hand Damage: 61 to 146",
            "Durability: 70 of 70",
            "Required Strength: 103",
            "Reouired Level: 57",
            "Mace Class - Very Fast Attack Speed",
            "+1 to All Skills",
            "+40% Increased Attack Speed",
            "+285% Enhanced Damage",
            "+2 to Attack Rating",
            "Adds 5-30 Fire Damage",
            "7% Life stolen per hit",
            "+1 to Sanctuary (Paladin Only)",
            "+6 to Battle Command",
            "+2 to Battle Orders",
            "+1 to Battle Cry",
            "Prevent Monster Heal",
            "Replenish Life +12",
            "30% Better Chance of Getting Magic Items",
            "+50% Damage to Undead",
            "Socketed (5)",
        ],
    },
    {
        "quality": "Set",
        "name": "Guillaume's Face",
        "base": "Winged Helm",
        "slot": "Helm",
        "tier": "Exceptional",
        "requirements": {"strength": 115, "level": 34},
        "stats": {"defense": [217]},
        "affixes": [
            ("+#% Faster Hit Recovery", [30]),
            ("+#% Chance of Crushing Blow", [35]),
            ("+#% Deadly Strike", [15]),
            ("+#% Enhanced Defense", [120]),
            ("+# to Strength", [15]),
            ("#% Better Chance of Getting Magic Items", [24]),
            ("Socketed (#)", [1]),
        ],
        "tooltip": [
            "Guillaume's Face",
            "Winged Helm",
            "Defense: 217",
            "Durability: 38 of 40",
            "Required Strength: 115",
            "Reouired Level: 34",
            "+30% Faster Hit Recovery",
            "+35% Chance of Crushing Blow",
            "+15% Deadly Strike",
            "+120% Enhanced Defense",
            "+15 to Strength",
            "24% Better Chance of Getting Magic Items",
            "Socketed (1)",
        ],
    },
    {
        "quality": "Set",
        "name": "Naj's Puzzler",
        "base": "Elder Staff",
        "slot": "Staff",
        "tier": "Elite",
        "requirements": {"strength": 44, "dexterity": 37, "level": 78},
        "stats": {"two_hand_damage": [200, 232]},
        "affixes": [
            ("+# to All Skills", [1]),
            ("+#% Faster Cast Rate", [30]),
            ("+#% Enhanced Damage", [150]),
            ("Adds #-# Lightning Damage", [6, 45]),
            ("+# to Energy", [35]),
            ("+# to Mana", [70]),
            ("Level # [Skill] (#/# Charges)", [11, "Teleport", 13, 69]),
            ("+#% Damage to Undead", [50]),
        ],
        "tooltip": [
            "nNaj's Puzzler",
            "Elder Staff",
            "two-hand Damage: 200 tao 232",
            "Staff Class - Normal attack Speed",
            "Durability: 25 of 35",
            "Required Dexterity: 37",
            "Required Strength: 44",
            "Required Level: 78",
            "+1 to all Skills",
            "+30% Faster Cast Rate",
            "+150% Enhanced Damage",
            "Adds 6-45 Lightning Damage",
            "+35 to Energy",
            "+70 to Mana",
            "Level 11 Teleport (13/69 Charges)",
            "+50% Damage to Undead",
        ],
    },
    {
        "quality": "Unique",
        "name": "Mara's Kaleidoscope",
        "base": "Amulet",
        "slot": "Amulet",
        "tier": "Normal",
        "requirements": {"level": 67},
        "stats": {},
        "affixes": [
            ("+# to All Skills", [2]),
            ("+# to all Attributes", [5]),
            ("All Resistances +#", [21]),
        ],
        "tooltip": [
            "Mara's Kaleidoscope",
            "Amulet",
            "Required Level: 67",
            "+2 to all Skills",
            "+5 to all Attributes",
            "All Resistances +21",
        ],
    },
    {
        "quality": "Unique",
        "name": "Bartuc's Cut-throat",
        "base": "Runic Talons",
        "slot": "Katar",
        "tier": "Elite",
        "requirements": {"class": "Assassin", "strength": 115, "dexterity": 115, "level": 67},
        "stats": {"one_hand_damage": [105, 197]},
        "affixes": [
            ("+# to Martial Arts (Assassin only)", [1]),
            ("+# to Assassin Skill Levels", [2]),
            ("+#% Faster Hit Recovery", [30]),
            ("+#% Enhanced Damage", [236]),
            ("Adds #-# Damage", [25, 50]),
            ("#% Bonus to Attack Rating", [20]),
            ("#% Life stolen per hit", [9]),
            ("+# to Strength", [20]),
            ("+# to Dexterity", [25]),
            ("Socketed (#)", [1]),
        ],
        "tooltip": [
            "Storm's Bartuc's Cut-throat",
            "Runic Talons",
            "Oone-hand Damage: 105 to 197",
            "Durability: 43 of 69",
            "(Assassin Only)",
            "Required Dexterity: 11S",
            "Reouired Strength: 11S",
            "Required Level: 67",
            "Claw Class - Very Fast Attack Speed",
            "+1 to Martial arts (Assassin Only]",
            "+2 to Assassin Skill Levels",
            "+30% Faster Hit Recovery",
            "+236% Enhanced Damage",
            "Adds 25-50 Damage",
            "20% Bonus to Attack Rating",
            "9% Life stolen per hit",
            "+20 to Strength",
            "+25 to Dexterity",
            "Socketed (1)",
        ],
    },
    {
        "quality": "Unique",
        "name": "Gheed's Fortune",
        "base": "Grand Charm",
        "slot": "Inventory",
        "tier": "Normal",
        "requirements": {"level": 62},
        "stats": {},
        "affixes": [
            ("#% Extra Gold from Monsters", [138]),
            ("Reduces all Vendor Prices #%", [15]),
            ("#% Better Chance of Getting Magic Items", [30]),
        ],
        "tooltip": [
            "Gheed's Fortune",
            "Grand Charm",
            "Keep In Inventory to Gain Bonus",
            "Required Level: 62",
            "138% Extra Gold from Monsters",
            "Reduces all Vendor Prices 15%",
            "30% Better Chance of Getting Magic Items",
        ],
    },
    {
        "quality": "Unique",
        "name": "Andariel's Visage",
        "base": "Demonhead",
        "slot": "Helm",
        "tier": "Elite",
        "requirements": {"strength": 102, "level": 83},
        "stats": {"defense": [358]},
        "affixes": [
            ("#% Chance to cast level # [Skill] when struck", [15, 15, "Poison Nova"]),
            ("+# to All Skills", [2]),
            ("+#% Increased Attack Speed", [20]),
            ("#% Life stolen per hit", [8]),
            ("+#% Enhanced Defense", [131]),
            ("+# to Strength", [25]),
            ("+#% to Maximum Poison Resist", [10]),
            ("Poison Resist +#%", [70]),
            ("Level # [Skill] (#/# Charges)", [3, "Venom", 20, 20]),
            ("Socketed (#)", [1]),
        ],
        "tooltip": [
            "Andariel's Visage",
            "Demonhead",
            "\"Ral'",
            "Defense: 358",
            "Durability: 20 of 20",
            "Required Strength: 102",
            "Required Level: 83",
            "15% Chance to Cast Level 15 Poison Nova When struck",
            "+2 to all Skills",
            "+20% Increased Attack Speed",
            "8% Life stolen per hit",
            "+131% Enhanced Defense",
            "+25 to Strength",
            "+10% to Maximum Poison Resist",
            "Poison Resist +70%",
            "Level 3 Venom (20/20 Charges)",
            "Socketed (1)",
        ],
    },
    {
        "quality": "Unique",
        "name": "Hellfire Torch",
        "base": "Large Charm",
        "slot": "Inventory",
        "tier": "Normal",
        "requirements": {"level": 75},
        "stats": {},
        "affixes": [
            ("#% Chance to cast level # [Skill] on striking", [5, 10, "Firestorm"]),
            ("+# to Assassin Skill Levels", [3]),
            ("+# to all Attributes", [20]),
            ("All Resistances +#", [14]),
            ("+# to Light Radius", [8]),
            ("Level # [Skill] (#/# Charges)", [30, "Hydra", 10, 10]),
        ],
        "tooltip": [
            "Hellfire Torch",
            "Large Charm",
            "Keep In Inventory to Gain Bonus",
            "Required Level: 75",
            "5% Chance to cast level 10 Firestorm on Striking",
            "+3 to Assassin Skill Levels",
            "+20 to all Attributes",
            "All Resistances +14",
            "+8 to Light Radius",
            "Level 30 Hydra (10/10 Charges)",
        ],
    },
    {
        "quality": "Unique",
        "name": "Annihilus",
        "base": "Small Charm",
        "slot": "Inventory",
        "tier": "Normal",
        "requirements": {"level": 70},
        "stats": {},
        "affixes": [
            ("+# to All Skills", [1]),
            ("+# to all Attributes", [12]),
            ("All Resistances +#", [18]),
            ("+#% to Experience Gained", [5]),
        ],
        "tooltip": [
            "Annihilus",
            "Small Charm",
            "Keep in Inventory to Gain Bonus",
            "Required Level: 70",
            "+1 to all Skills",
            "+12 to all Attributes",
            "All Resistances +18",
            "+5% to Experience Gained",
        ],
    },
]


@pytest.mark.parametrize("item", ITEMS)
def test_parse_item_lines_to_json(item):
    parse_itemed = ItemParser(item["tooltip"]).parse_item_lines_to_json()
    assert item["tooltip"] == parse_itemed["tooltip"]
    assert item["quality"] == parse_itemed["quality"]
    assert item["name"] == parse_itemed["name"]
    assert item["base"] == parse_itemed["base"]
    assert item["slot"] == parse_itemed["slot"]
    assert item["tier"] == parse_itemed["tier"]
    assert item["requirements"] == parse_itemed["requirements"]
    assert item["stats"] == parse_itemed["stats"]
    assert item["affixes"] == parse_itemed["affixes"]
