import 'package:wolf_3d_dart/wolf_3d_data_types.dart';
import 'package:wolf_3d_dart/src/entities/entity.dart';

class Decorative extends Entity {
  Decorative({
    required super.x,
    required super.y,
    required super.spriteIndex,
    required super.mapId,
    super.state = EntityState.staticObj, // Defaults to static
  });

  // Checks if the Map ID belongs to a standard decoration
  static bool isDecoration(int objId) {
    // ID 124 is a dead guard in WL1, but an SS guard in WL6.
    // However, for spawning purposes, if the SS trySpawn fails,
    // we only want to treat it as a decoration if it's not a live actor.
    if (objId == 124 || objId == 125) return true;

    if (objId >= 23 && objId <= 70) {
      // Exclude collectibles defined in MapObject
      if ((objId >= 43 && objId <= 44) || (objId >= 47 && objId <= 56)) {
        return false;
      }
      return true;
    }
    return false;
  }

  static int getSpriteIndex(int objId) {
    if (objId == 124) return 95; // Dead guard sprite index
    if (objId == 125) return 96; // Dead Aardwolf/Other body

    // Standard decorations are typically offset by 21 in the VSWAP
    return objId - 21;
  }

  static Decorative? trySpawn(
    int objId,
    double x,
    double y,
    Difficulty difficulty, {
    bool isSharewareMode = false,
  }) {
    // 2. Standard props (Table, Lamp, etc) use the tiered check
    if (!MapObject.isDifficultyAllowed(objId, difficulty)) return null;

    if (isDecoration(objId)) {
      return Decorative(
        x: x,
        y: y,
        spriteIndex: getSpriteIndex(objId),
        mapId: objId,
        state: objId == 124 ? EntityState.dead : EntityState.staticObj,
      );
    }

    // Not a decoration!
    return null;
  }
}
