import '../enums.dart';

class ItemModifier {
  final String prefix;
  final Map<StatType, int> statChanges;
  final List<EquipmentSlot>? allowedSlots; // Null means allowed for all slots
  final double multiplier; // For percent-based modifiers (Normal rarity)
  final int weight; // Selection weight

  const ItemModifier({
    required this.prefix, 
    this.statChanges = const {}, 
    this.allowedSlots,
    this.multiplier = 1.0,
    this.weight = 1,
  });
}

class ItemPrefixTable {
  static const List<ItemModifier> normalPrefixes = [
    ItemModifier(prefix: "Crude", multiplier: 0.9, weight: 25),
    ItemModifier(prefix: "Old", multiplier: 0.95, weight: 25),
    ItemModifier(prefix: "", multiplier: 1.0, weight: 25), // Standard
    ItemModifier(prefix: "High-quality", multiplier: 1.1, weight: 25),
  ];

  static const List<ItemModifier> magicPrefixes = [
    // Weapons
    ItemModifier(
      prefix: "Sharp", 
      statChanges: {StatType.atk: 2}, 
      allowedSlots: [EquipmentSlot.weapon, EquipmentSlot.accessory]
    ),
    ItemModifier(
      prefix: "Heavy", 
      statChanges: {StatType.atk: 3}, 
      allowedSlots: [EquipmentSlot.weapon]
    ),
    ItemModifier(
      prefix: "Swift", 
      statChanges: {StatType.atk: 1}, 
      allowedSlots: [EquipmentSlot.weapon, EquipmentSlot.accessory]
    ),
    
    // Armor / Shield
    ItemModifier(
      prefix: "Sturdy", 
      statChanges: {StatType.maxHp: 10},
      allowedSlots: [EquipmentSlot.armor, EquipmentSlot.shield, EquipmentSlot.accessory]
    ),
    ItemModifier(
      prefix: "Hard", 
      statChanges: {StatType.defense: 1},
      allowedSlots: [EquipmentSlot.armor, EquipmentSlot.shield]
    ),
    
    // General / Accessory
    ItemModifier(
      prefix: "Lucky", 
      statChanges: {StatType.luck: 5},
      allowedSlots: null // All slots (e.g. Lucky Sword is fine)
    ),
  ];

  static const List<ItemModifier> rarePrefixes = [
    // Offensive (Weapons/Accessories)
    ItemModifier(
      prefix: "Deadly", 
      statChanges: {StatType.atk: 5, StatType.luck: 5},
      allowedSlots: [EquipmentSlot.weapon, EquipmentSlot.accessory]
    ),
    ItemModifier(
      prefix: "Vicious", 
      statChanges: {StatType.atk: 6, StatType.maxHp: -5},
      allowedSlots: [EquipmentSlot.weapon]
    ),
    ItemModifier(
      prefix: "Brutal", 
      statChanges: {StatType.atk: 8},
      allowedSlots: [EquipmentSlot.weapon]
    ),
    
    // Defensive (Armor/Shields/Accessories)
    ItemModifier(
      prefix: "Guardian's", 
      statChanges: {StatType.defense: 3, StatType.maxHp: 20},
      allowedSlots: [EquipmentSlot.armor, EquipmentSlot.shield, EquipmentSlot.accessory]
    ),
    ItemModifier(
      prefix: "Ancient", 
      statChanges: {StatType.defense: 2, StatType.maxHp: 15},
      allowedSlots: [EquipmentSlot.armor, EquipmentSlot.shield]
    ),
    ItemModifier(
      prefix: "Divine", 
      statChanges: {StatType.defense: 2, StatType.maxHp: 30, StatType.luck: 5},
      allowedSlots: [EquipmentSlot.armor, EquipmentSlot.shield, EquipmentSlot.accessory]
    ),
    
    // Versatile
    ItemModifier(
      prefix: "Heroic", 
      statChanges: {StatType.atk: 2, StatType.defense: 2, StatType.maxHp: 10},
      allowedSlots: null
    ),
  ];
  
  // Special names for Rare/Unique replacements (Optional usage)
  static const List<String> rareNames = [
    "Earthshatter", "Soulrender", "Widowmaker", "Lightbringer"
  ];
}
