
import MagmaKing from './magmaKing/MagmaKing';
import SeaSentryBoss from './seaSentry/SeaSentryBoss';
import Skulkosaurus from './skulkosaurus/skulkosaurus';
import TheVoid from './theVoid/TheVoid';

class BossManager {
  constructor() {
    this.bossRegistry = new Map(); // Maps entityId to boss instance
    this.bossTypes = new Map([
      ["lv_mo:magma_king", MagmaKing],
      ["lv_mo:sea_sentry", SeaSentryBoss],
      ["lv_mo:skulkosaurus", Skulkosaurus],
      ["lv_mo:the_void", TheVoid]
      // Add additional boss types here
    ]);
  }

  // Register a new boss when it spawns
  registerBoss(entityId, typeId) {
    const BossClass = this.bossTypes.get(typeId);
    if (BossClass) {
      const bossInstance = new BossClass(entityId); // Instantiate the boss
      this.bossRegistry.set(entityId, bossInstance); // Add boss to registry
      //console.warn(`Registered boss with ID: ${entityId} of type ${typeId}`);
      bossInstance.init();  // Call init method to start any behaviors
    } else {
      //console.warn(`Boss type ${typeId} not found in registry.`);
    }
  }

  // Remove boss when it dies
  removeBoss(entityId) {
    if (this.bossRegistry.has(entityId)) {
      const boss = this.bossRegistry.get(entityId);
      //console.warn(JSON.stringify(boss))
      boss.die();  // Call die method to handle any cleanup
      this.bossRegistry.delete(entityId);
      //console.warn(`Boss with ID: ${entityId} removed.`);
    }
  }

  // Load existing boss if it spawns again
  loadBoss(entityId, typeId) {
    if (!this.bossRegistry.has(entityId)) {
      this.registerBoss(entityId, typeId);
    } else {
      // If the boss is already registered, initialize it again if necessary
      const boss = this.bossRegistry.get(entityId);
      boss.init(); // Ensure initialization even if it's already registered
    }
  }
}

export default new BossManager();
