// ─── Equipment Types ───────────────────────────────────────────────────────
import type { EquipmentSlot } from './equipmentSlot';

// Legacy EquipmentDef for backward compatibility
export interface EquipmentDef {
  id: string;
  name: string;
  slot: EquipmentSlot;
  rarity: 'common' | 'uncommon' | 'rare' | 'epic' | 'legendary' | 'mythic';
  stats: Record<string, number>;
  durability: number;
  maxDurability: number;
  element?: string;
}

// Equipment Instance (actual equipped item with enchantments)
export interface EquipmentInstance {
  instanceId: string;          // Unique ID for this specific item
  typeId: string;              // Reference to EquipmentType (e.g., 'basicStaff')
  name: string;                // Display name (defaults to type name)
  enchantments: AppliedEnchantment[];
  usedCapacity: number;        // Currently used capacity
  totalCapacity: number;       // Base capacity + bonuses
  rarity: 'common' | 'uncommon' | 'rare' | 'epic' | 'legendary' | 'mythic';
  quality: number;             // 0-100, affects capacity efficiency
  tags: string[];              // Tags for item state (e.g., 'Ready for Enchantment')
  weaponMana?: number;         // Current mana stored in weapon (for weapon enchantments)
  weaponManaMax?: number;      // Max mana the weapon can store
  weaponManaRegen?: number;    // Mana regen per hour for weapon
  weaponManaType?: string;     // Type of mana the weapon stores
  activeWeaponEnchant?: string; // Active weapon enchantment (for magic swords)
}

export interface AppliedEnchantment {
  effectId: string;            // Reference to EnchantmentEffectDef
  stacks: number;              // Number of times this effect is applied
  actualCost: number;          // Actual capacity cost (after efficiency)
}

// Enchantment Design (saved design for later application)
export interface EnchantmentDesign {
  id: string;
  name: string;
  equipmentType: string;       // Which equipment type this is designed for
  effects: DesignEffect[];
  totalCapacityUsed: number;
  designTime: number;          // Hours required to design
  created: number;             // Timestamp
}

export interface DesignEffect {
  effectId: string;
  stacks: number;
  capacityCost: number;
}

// Crafting Progress States
export interface DesignProgress {
  designId: string;
  progress: number;            // Hours spent designing
  required: number;            // Total hours needed
  // Design data stored during progress
  name: string;
  equipmentType: string;
  effects: DesignEffect[];
}

export interface PreparationProgress {
  equipmentInstanceId: string;
  progress: number;            // Hours spent preparing
  required: number;            // Total hours needed
  manaCostPaid: number;        // Mana cost already paid
}

export interface ApplicationProgress {
  equipmentInstanceId: string;
  designId: string;
  progress: number;            // Hours spent applying
  required: number;            // Total hours needed
  manaPerHour: number;         // Mana cost per hour
  paused: boolean;
  manaSpent: number;           // Total mana spent so far
}

// Equipment crafting progress (from blueprints)
export interface EquipmentCraftingProgress {
  blueprintId: string;
  equipmentTypeId: string;
  progress: number;            // Hours spent crafting
  required: number;            // Total hours needed
  manaSpent: number;           // Total mana spent so far
}

// Equipment spell state (for multi-spell casting)
export interface EquipmentSpellState {
  spellId: string;
  sourceEquipment: string;     // Equipment instance ID
  castProgress: number;        // 0-1 progress toward next cast
}

export interface BlueprintDef {
  id: string;
  name: string;
  tier: number;
  slot: string;
  stats: Record<string, number>;
  studyTime: number;
  craftTime: number;
  craftCost: number;
  discovered: boolean;
  learned: boolean;
}

// Loot inventory for materials and blueprints
export interface LootInventory {
  materials: Record<string, number>;  // materialId -> count
  blueprints: string[];               // blueprint IDs discovered
}
