import 'dart:math';
import '../enums.dart';

class NameGenerator {
  static final Random _random = Random();

  // Adjectives suitable for powerful items
  static const List<String> _adjectives = [
    "Crimson",
    "Shadow",
    "Azure",
    "Burning",
    "Frozen",
    "Ancient",
    "Cursed",
    "Blessed",
    "Savage",
    "Eternal",
    "Dark",
    "Holy",
    "Storm",
    "Void",
    "Crystal",
    "Iron",
    "Blood",
    "Night",
  ];

  // Nouns specifically for Weapons
  static const List<String> _weaponNouns = [
    "Fang",
    "Claw",
    "Reaper",
    "Breaker",
    "Slayer",
    "Edge",
    "Blade",
    "Spike",
    "Crusher",
    "Whisper",
    "Howl",
    "Strike",
    "Bane",
    "Fury",
    "Vengeance",
    "Thorn",
  ];

  // Nouns specifically for Armor
  static const List<String> _armorNouns = [
    "Guard",
    "Wall",
    "Shelter",
    "Skin",
    "Scale",
    "Plate",
    "Bulwark",
    "Veil",
    "Shroud",
    "Ward",
    "Barrier",
    "Bastion",
    "Mantle",
    "Aegis",
    "Carapace",
  ];

  // Nouns specifically for Shields
  static const List<String> _shieldNouns = [
    "Wall",
    "Barrier",
    "Aegis",
    "Defender",
    "Blockade",
    "Resolve",
    "Sanctuary",
    "Buckler",
    "Tower",
    "Gate",
  ];

  // Nouns specifically for Accessories
  static const List<String> _accessoryNouns = [
    "Heart",
    "Soul",
    "Eye",
    "Tear",
    "Spark",
    "Ember",
    "Drop",
    "Mark",
    "Sign",
    "Omen",
    "Wish",
    "Star",
  ];

  static String generateName(EquipmentSlot slot) {
    String adjective = _adjectives[_random.nextInt(_adjectives.length)];
    String noun = "";

    switch (slot) {
      case EquipmentSlot.weapon:
        noun = _weaponNouns[_random.nextInt(_weaponNouns.length)];
        break;
      case EquipmentSlot.armor:
        noun = _armorNouns[_random.nextInt(_armorNouns.length)];
        break;
      case EquipmentSlot.shield:
        noun = _shieldNouns[_random.nextInt(_shieldNouns.length)];
        break;
      case EquipmentSlot.accessory:
        noun = _accessoryNouns[_random.nextInt(_accessoryNouns.length)];
        break;
      case EquipmentSlot.consumable:
        noun = "Potion";
        break;
    }

    // 20% Chance for "Noun of Noun" format (e.g. "Fang of Shadow")
    if (_random.nextDouble() < 0.2) {
      String suffixNoun =
          _adjectives[_random.nextInt(
            _adjectives.length,
          )]; // Reuse adjectives as nouns sometimes works (e.g. "of Blood")
      // Better: use a subset of adjectives that work as nouns or generic nouns
      return "$noun of $suffixNoun";
    }

    return "$adjective $noun";
  }
}
