// ─── Mana Enchantment Effects ────────────────────────────────────────────────
// All mana-related enchantment effects that can be applied to equipment

// Import ELEMENTS to get the list of elements for per-element capacity effects
import { ELEMENTS } from '../../constants';

import type { EquipmentCategory } from '../equipment'
import type { EnchantmentEffectDef } from '../enchantment-types'

// Helper to define allowed equipment categories for each effect type
const MANA_EQUIPMENT: EquipmentCategory[] = ['caster', 'catalyst', 'head', 'body', 'accessory']
const WEAPON_EQUIPMENT: EquipmentCategory[] = ['caster', 'catalyst', 'sword']  // All main hand equipment

export const MANA_EFFECTS: Record<string, EnchantmentEffectDef> = {
  // ═══════════════════════════════════════════════════════════════════════════
  // MANA EFFECTS - Boost mana capacity and regeneration
  // ═══════════════════════════════════════════════════════════════════════════
  
  mana_cap_50: {
    id: 'mana_cap_50',
    name: 'Mana Reserve',
    description: '+50 maximum mana',
    category: 'mana',
    baseCapacityCost: 20,
    maxStacks: 3,
    allowedEquipmentCategories: MANA_EQUIPMENT,
    effect: { type: 'bonus', stat: 'maxMana', value: 50 }
  },
  mana_cap_100: {
    id: 'mana_cap_100',
    name: 'Mana Reservoir',
    description: '+100 maximum mana',
    category: 'mana',
    baseCapacityCost: 35,
    maxStacks: 3,
    allowedEquipmentCategories: MANA_EQUIPMENT,
    effect: { type: 'bonus', stat: 'maxMana', value: 100 }
  },
  mana_regen_1: {
    id: 'mana_regen_1',
    name: 'Trickle',
    description: '+1 mana per hour regeneration',
    category: 'mana',
    baseCapacityCost: 15,
    maxStacks: 5,
    allowedEquipmentCategories: MANA_EQUIPMENT,
    effect: { type: 'bonus', stat: 'regen', value: 1 }
  },
  mana_regen_2: {
    id: 'mana_regen_2',
    name: 'Stream',
    description: '+2 mana per hour regeneration',
    category: 'mana',
    baseCapacityCost: 28,
    maxStacks: 4,
    allowedEquipmentCategories: MANA_EQUIPMENT,
    effect: { type: 'bonus', stat: 'regen', value: 2 }
  },
  mana_regen_5: {
    id: 'mana_regen_5',
    name: 'River',
    description: '+5 mana per hour regeneration',
    category: 'mana',
    baseCapacityCost: 50,
    maxStacks: 3,
    allowedEquipmentCategories: MANA_EQUIPMENT,
    effect: { type: 'bonus', stat: 'regen', value: 5 }
  },
  click_mana_1: {
    id: 'click_mana_1',
    name: 'Mana Tap',
    description: '+1 mana per click',
    category: 'mana',
    baseCapacityCost: 20,
    maxStacks: 5,
    allowedEquipmentCategories: MANA_EQUIPMENT,
    effect: { type: 'bonus', stat: 'clickMana', value: 1 }
  },
  click_mana_3: {
    id: 'click_mana_3',
    name: 'Mana Surge',
    description: '+3 mana per click',
    category: 'mana',
    baseCapacityCost: 35,
    maxStacks: 3,
    allowedEquipmentCategories: MANA_EQUIPMENT,
    effect: { type: 'bonus', stat: 'clickMana', value: 3 }
  },

  // ═══════════════════════════════════════════════════════════════════════════
  // WEAPON MANA EFFECTS - Enchanter level 3+ unlocks these
  // These add mana capacity and regeneration to weapons for their enchantments
  // ═══════════════════════════════════════════════════════════════════════════
  
  weapon_mana_cap_20: {
    id: 'weapon_mana_cap_20',
    name: 'Mana Cell',
    description: '+20 weapon mana capacity (for weapon enchantments)',
    category: 'mana',
    baseCapacityCost: 25,
    maxStacks: 5,
    allowedEquipmentCategories: WEAPON_EQUIPMENT,
    effect: { type: 'bonus', stat: 'weaponManaMax', value: 20 }
  },
  weapon_mana_cap_50: {
    id: 'weapon_mana_cap_50',
    name: 'Mana Vessel',
    description: '+50 weapon mana capacity (for weapon enchantments)',
    category: 'mana',
    baseCapacityCost: 50,
    maxStacks: 3,
    allowedEquipmentCategories: WEAPON_EQUIPMENT,
    effect: { type: 'bonus', stat: 'weaponManaMax', value: 50 }
  },
  weapon_mana_cap_100: {
    id: 'weapon_mana_cap_100',
    name: 'Mana Core',
    description: '+100 weapon mana capacity (for weapon enchantments)',
    category: 'mana',
    baseCapacityCost: 80,
    maxStacks: 2,
    allowedEquipmentCategories: WEAPON_EQUIPMENT,
    effect: { type: 'bonus', stat: 'weaponManaMax', value: 100 }
  },
  weapon_mana_regen_1: {
    id: 'weapon_mana_regen_1',
    name: 'Mana Wick',
    description: '+1 weapon mana regeneration per hour',
    category: 'mana',
    baseCapacityCost: 20,
    maxStacks: 5,
    allowedEquipmentCategories: WEAPON_EQUIPMENT,
    effect: { type: 'bonus', stat: 'weaponManaRegen', value: 1 }
  },
  weapon_mana_regen_2: {
    id: 'weapon_mana_regen_2',
    name: 'Mana Siphon',
    description: '+2 weapon mana regeneration per hour',
    category: 'mana',
    baseCapacityCost: 35,
    maxStacks: 3,
    allowedEquipmentCategories: WEAPON_EQUIPMENT,
    effect: { type: 'bonus', stat: 'weaponManaRegen', value: 2 }
  },
  weapon_mana_regen_5: {
    id: 'weapon_mana_regen_5',
    name: 'Mana Well',
    description: '+5 weapon mana regeneration per hour',
    category: 'mana',
    baseCapacityCost: 60,
    maxStacks: 2,
    allowedEquipmentCategories: WEAPON_EQUIPMENT,
    effect: { type: 'bonus', stat: 'weaponManaRegen', value: 5 }
  },

  // ═══════════════════════════════════════════════════════════════════════════
  // PER-ELEMENT CAPACITY EFFECTS - Boosts capacity for specific mana types
  // ═══════════════════════════════════════════════════════════════════════════
  
  // Helper to create per-element capacity effects for a given element
  // Creates 3 tiers: +10 (5 stacks), +25 (3 stacks), +50 (2 stacks)
  ...Object.fromEntries(
    Object.entries(ELEMENTS)
      .filter(([, def]) => def.cat !== 'utility') // Skip utility elements like transference
      .flatMap(([elemId, elemDef]) => {
        const capName = elemId.charAt(0).toUpperCase() + elemId.slice(1);
        return [
          [`${elemId}_cap_10`, {
            id: `${elemId}_cap_10`,
            name: `${capName} Reservoir`,
            description: `+10 ${elemDef.name} mana capacity`,
            category: 'mana',
            baseCapacityCost: 30,
            maxStacks: 5,
            allowedEquipmentCategories: MANA_EQUIPMENT,
            effect: { type: 'bonus', stat: `elementCap_${elemId}`, value: 10 }
          }],
          [`${elemId}_cap_25`, {
            id: `${elemId}_cap_25`,
            name: `${capName} Basin`,
            description: `+25 ${elemDef.name} mana capacity`,
            category: 'mana',
            baseCapacityCost: 60,
            maxStacks: 3,
            allowedEquipmentCategories: MANA_EQUIPMENT,
            effect: { type: 'bonus', stat: `elementCap_${elemId}`, value: 25 }
          }],
          [`${elemId}_cap_50`, {
            id: `${elemId}_cap_50`,
            name: `${capName} Wellspring`,
            description: `+50 ${elemDef.name} mana capacity`,
            category: 'mana',
            baseCapacityCost: 100,
            maxStacks: 2,
            allowedEquipmentCategories: MANA_EQUIPMENT,
            effect: { type: 'bonus', stat: `elementCap_${elemId}`, value: 50 }
          }],
        ];
      })
  ),
};
