// ─── Crafting Store Types ────────────────────────────────────────────────────
import type {
  DesignProgress,
  PreparationProgress,
  ApplicationProgress,
  EquipmentCraftingProgress,
  EnchantmentDesign,
  EquipmentInstance,
  DesignEffect,
} from '../types';
import type { EquipmentSlot } from '../types/equipmentSlot';

export interface CraftingError {
  code: string;
  message: string;
  timestamp: number;
}

export type CraftingAttunement = 'fabricator' | 'enchanter';

export interface CraftingState {
  designProgress: DesignProgress | null;
  designProgress2: DesignProgress | null;
  preparationProgress: PreparationProgress | null;
  applicationProgress: ApplicationProgress | null;
  equipmentCraftingProgress: EquipmentCraftingProgress | null;
  completedEnchantmentDesigns: EnchantmentDesign[];
  unlockedEffects: string[];
  unlockedRecipes: string[];
  equipmentInstances: Record<string, EquipmentInstance>;
  equippedInstances: Record<string, string | null>;
  lootInventory: {
    materials: Record<string, number>;
    blueprints: string[];
  };
  enchantmentSelection: {
    selectedEquipmentType: string | null;
    selectedEffects: DesignEffect[];
    designName: string;
    selectedDesign: string | null;
    selectedEquipmentInstance: string | null;
  };
  lastError: CraftingError | null;
  activeCraftingSubTab: CraftingAttunement;
}

export interface CraftingActions {
  setDesignProgress: (progress: DesignProgress | null) => void;
  setDesignProgress2: (progress: DesignProgress | null) => void;
  setPreparationProgress: (progress: PreparationProgress | null) => void;
  setApplicationProgress: (progress: ApplicationProgress | null) => void;
  setEquipmentCraftingProgress: (progress: EquipmentCraftingProgress | null) => void;
  setActiveCraftingSubTab: (tab: CraftingAttunement) => void;
  startDesigningEnchantment: (name: string, equipmentTypeId: string, effects: DesignEffect[]) => boolean;
  cancelDesign: (slot?: 1 | 2) => void;
  saveDesign: (design: EnchantmentDesign) => void;
  deleteDesign: (designId: string) => void;
  startApplying: (equipmentInstanceId: string, designId: string) => boolean;
  pauseApplication: () => void;
  resumeApplication: () => void;
  cancelApplication: () => void;
  startPreparing: (equipmentInstanceId: string) => boolean;
  cancelPreparation: () => void;
  deleteMaterial: (materialId: string, amount: number) => void;
  deleteEquipmentInstance: (instanceId: string) => void;
  equipItem: (instanceId: string, slot: EquipmentSlot) => boolean;
  unequipItem: (slot: EquipmentSlot) => void;
  startCraftingEquipment: (blueprintId: string) => boolean;
  startFabricatorCrafting: (recipeId: string) => boolean;
  craftMaterial: (recipeId: string) => boolean;
  cancelEquipmentCrafting: () => void;
  setSelectedEquipmentType: (type: string | null) => void;
  setSelectedEffects: (effects: DesignEffect[]) => void;
  setDesignName: (name: string) => void;
  setSelectedDesign: (id: string | null) => void;
  setSelectedEquipmentInstance: (id: string | null) => void;
  resetEnchantmentSelection: () => void;
  clearLastError: () => void;
  unlockEffects: (effectIds: string[]) => void;
  unlockRecipes: (recipeIds: string[]) => void;
  processEquipmentCraftingTick: () => { completed: boolean; logMessage?: string };
  resetCrafting: () => void;
}

export type CraftingStore = CraftingState & CraftingActions;
