// @ts-check
import { FogDweller } from "./fog_dweller";

/**
 * Manages the fog dweller objects. Provides functions for spawning and keeping track of them.
 */
export class FogDwellerManager {
	/**
	 * @private
	 * @static
	 * @type {Map<string, FogDweller>}
	 */
	static entityRegistry = new Map();

	/**
	 * Adds a fog dweller to the entity registry.
	 * @param {FogDweller} fogDweller
	 */
	static setInRegistry(fogDweller) {
		FogDwellerManager.entityRegistry.set(fogDweller.entity.id, fogDweller);
	}

	/**
	 * Returns the FogDweller instance from the entity registry.
	 * @param {string} entityId
	 */
	static getFromRegistry(entityId) {
		return FogDwellerManager.entityRegistry.get(entityId);
	}

	/**
	 * Removes the FogDweller instance from the entity registry.
	 * @param {string} entityId
	 */
	static removeFromRegistry(entityId) {
		FogDwellerManager.entityRegistry.delete(entityId);
	}

	/**
	 * Checks if the player is a target of any fog dweller.
	 * @param {string} playerId
	 */
	static isFogDwellerTarget(playerId) {
		for (const fogDweller of FogDwellerManager.entityRegistry.values()) {
			if (fogDweller.target?.id === playerId) {
				return true;
			}
		}
		return false;
	}
}
