import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
import 'package:wolf_3d_entities/wolf_3d_entities.dart';

abstract class MapObject {
  // --- Player Spawns ---
  static const int playerNorth = 19;
  static const int playerEast = 20;
  static const int playerSouth = 21;
  static const int playerWest = 22;

  // --- Static Decorations ---
  static const int waterPuddle = 23;
  static const int greenBarrel = 24;
  static const int chairTable = 25;
  static const int floorLamp = 26;
  static const int chandelier = 27;
  static const int hangingSkeleton = 28;
  static const int dogFoodDecoration = 29;
  static const int whiteColumn = 30;
  static const int pottedPlant = 31;
  static const int blueSkeleton = 32;
  static const int vent = 33;
  static const int kitchenCans = 34;
  static const int exitSign = 35;
  static const int brownPlant = 36;
  static const int bowl = 37;
  static const int armoredSuit = 38;
  static const int emptyCage = 39;
  static const int cageWithSkeleton = 40;
  static const int bones = 41;
  static const int goldenKeyBowl = 42;

  // --- Collectibles ---
  static const int goldKey = 43;
  static const int silverKey = 44;
  static const int bed = 45;
  static const int basket = 46;
  static const int food = 47;
  static const int medkit = 48;
  static const int ammoClip = 49;
  static const int machineGun = 50;
  static const int chainGun = 51;
  static const int cross = 52;
  static const int chalice = 53;
  static const int chest = 54;
  static const int crown = 55;
  static const int extraLife = 56;

  // --- Environmental ---
  static const int bloodPoolSmall = 57;
  static const int barrel = 58;
  static const int wellFull = 59;
  static const int wellEmpty = 60;
  static const int bloodPoolLarge = 61;
  static const int flag = 62;
  static const int aardwolfSign = 63;
  static const int bonesAndSkull = 64;
  static const int wallHanging = 65;
  static const int stove = 66;
  static const int spearRack = 67;
  static const int vines = 68;

  // --- Logic & Triggers ---
  static const int pushwallTrigger = 98;
  static const int secretExitTrigger = 99;
  static const int normalExitTrigger = 100;

  // --- Wall Textures (From VSWAP/MAPHEAD) ---
  static const int normalElevatorSwitch = 21;
  static const int secretElevatorSwitch = 41;

  // Bosses (Shared between WL1 and WL6)
  static const int bossHansGrosse = 214;

  // WL6 Exclusive Bosses
  static const int bossDrSchabbs = 215;
  static const int bossTransGrosse = 216;
  static const int bossUbermutant = 217;
  static const int bossDeathKnight = 218;
  static const int bossMechaHitler = 219;
  static const int bossHitlerGhost = 220;
  static const int bossGretelGrosse = 221;
  static const int bossGiftmacher = 222;
  static const int bossFettgesicht = 223;

  // --- Enemy Range Constants ---
  static const int guardStart = 108; // 108-143
  static const int dogStart = 144; // 144-179
  static const int ssStart = 180; // 180-215
  static const int mutantStart = 216; // 216-251
  static const int officerStart = 252; // 252-287

  // --- Missing Decorative Bodies ---
  static const int deadGuard = 124; // Decorative only in WL1
  static const int deadAardwolf = 125; // Decorative only in WL1

  static double getAngle(int id) {
    switch (id) {
      case playerNorth:
        return CardinalDirection.north.radians;
      case playerEast:
        return CardinalDirection.east.radians;
      case playerSouth:
        return CardinalDirection.south.radians;
      case playerWest:
        return CardinalDirection.west.radians;
    }

    if (id == bossHansGrosse) return 0.0;

    final EnemyType? type = EnemyType.fromMapId(id);
    if (type == null) return 0.0;

    // Because all enemies are in blocks of 4, modulo 4 gets the exact angle
    return CardinalDirection.fromEnemyIndex(id % 4).radians;
  }

  /// Determines if an object should be spawned on the current difficulty.
  static bool isDifficultyAllowed(int objId, Difficulty difficulty) {
    // 1. Dead bodies always spawn
    if (objId == deadGuard || objId == deadAardwolf) return true;

    // 2. If it's an enemy, we return true to let it pass through to the
    // Enemy.spawn factory. The factory will safely return null if the
    // enemy does not belong on this difficulty.
    if (EnemyType.fromMapId(objId) != null) {
      return true;
    }

    // 3. All non-enemy map objects (keys, ammo, puddles, plants)
    // are NOT difficulty-tiered. They always spawn.
    return true;
  }
}
