"""
Unit tests for Divine Weapons, Primal Bloodstones & World Lore Assets.
Strictly complies with Engineering Standards 2026.
"""

import os
import sys
import unittest
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent / "server"))

from server.world.weapon_catalog import get_base_weapon_catalog
from server.world.weapon_types import GripStyle, WeaponClass


class TestDivineWeaponsAndRelics(unittest.TestCase):
    def setUp(self) -> None:
        self.catalog = get_base_weapon_catalog()
        self.workspace_root = Path(__file__).resolve().parent.parent.parent
        self.assets_dir = self.workspace_root / "client" / "webapp" / "assets"

    def test_divine_weapons_catalog_entries(self) -> None:
        """Verifies 5 Divine Relic Weapons are registered with iLvl 85 requirements."""
        divine_keys = [
            "WPN_DIVINE_SWORD_XICH_HUYET",
            "WPN_DIVINE_AXE_THON_COT",
            "WPN_DIVINE_BOW_TICH_COT",
            "WPN_DIVINE_SPEAR_THAN_PHU",
            "WPN_DIVINE_STAFF_THAI_HU",
        ]
        for key in divine_keys:
            self.assertIn(key, self.catalog, f"Missing divine weapon: {key}")
            weapon = self.catalog[key]
            self.assertEqual(weapon.required_level, 85)
            self.assertEqual(weapon.grip_style, GripStyle.TWO_HANDED)
            self.assertGreater(weapon.max_damage, 300.0)
            self.assertIsNotNone(weapon.implicit_mod)
            self.assertGreater(weapon.implicit_mod.value, 0.0)

    def test_divine_weapons_assets_exist(self) -> None:
        """Verifies weapon icons and normal maps exist in client assets."""
        weapons = [
            "wpn_abyssal_chainguard_sword",
            "wpn_dragonbone_maw_greataxe",
            "wpn_spinal_recurve_greatbow",
            "wpn_runic_skullspear_halberd",
            "wpn_etheric_demonstaff",
        ]
        wpn_dir = self.assets_dir / "weapons"
        for w in weapons:
            png_p = wpn_dir / f"{w}.png"
            norm_p = wpn_dir / f"{w}_normal.png"
            self.assertTrue(png_p.exists(), f"Missing PNG: {png_p}")
            self.assertTrue(norm_p.exists(), f"Missing Normal Map: {norm_p}")
            self.assertGreater(png_p.stat().st_size, 1000)

    def test_primal_bloodstone_relics_assets_exist(self) -> None:
        """Verifies 6 Primal Relic Currencies and normal maps exist."""
        relics = [
            "curr_blood_soul_gem",
            "curr_nether_bone_nail_hq",
            "curr_primal_bone_seal_hq",
            "curr_chaos_bloodstone",
            "curr_void_mirror_shard",
            "curr_life_bone_marrow",
        ]
        curr_dir = self.assets_dir / "currencies"
        for r in relics:
            png_p = curr_dir / f"{r}.png"
            norm_p = curr_dir / f"{r}_normal.png"
            self.assertTrue(png_p.exists(), f"Missing Currency PNG: {png_p}")
            self.assertTrue(norm_p.exists(), f"Missing Normal Map: {norm_p}")
            self.assertGreater(png_p.stat().st_size, 1000)

    def test_loading_screens_and_banners_exist(self) -> None:
        """Verifies cinematic loading screens and panoramic banners exist."""
        load_dir = self.assets_dir / "loading"
        ban_dir = self.assets_dir / "banners"

        self.assertTrue((load_dir / "loading_forsaken_shore.jpg").exists())
        self.assertTrue((load_dir / "loading_eldritch_crypt.jpg").exists())
        self.assertTrue((ban_dir / "banner_deadlands_panorama.jpg").exists())

        # Check resolution and non-empty size
        self.assertGreater((load_dir / "loading_forsaken_shore.jpg").stat().st_size, 50000)
        self.assertGreater((ban_dir / "banner_deadlands_panorama.jpg").stat().st_size, 50000)


if __name__ == "__main__":
    unittest.main()
