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

enum CollectibleType { ammo, health, treasure, weapon, key }

class Collectible extends Entity {
  final CollectibleType type;

  Collectible({
    required super.x,
    required super.y,
    required super.spriteIndex,
    required super.mapId,
    required this.type,
  }) : super(state: EntityState.staticObj);

  // Define which Map IDs are actually items you can pick up
  static bool isCollectible(int objId) {
    return (objId >= 43 && objId <= 44) || // Keys
        (objId >= 47 && objId <= 56); // Health, Ammo, Weapons, Treasure, 1-Up
  }

  static CollectibleType _getType(int objId) {
    if (objId == 43 || objId == 44) return CollectibleType.key;
    if (objId == 47 || objId == 48) return CollectibleType.health;
    if (objId == 49) return CollectibleType.ammo;
    if (objId == 50 || objId == 51) return CollectibleType.weapon;
    return CollectibleType.treasure; // 52-56
  }

  static Collectible? trySpawn(
    int objId,
    double x,
    double y,
    Difficulty difficulty, {
    bool isSharewareMode = false,
  }) {
    if (isCollectible(objId)) {
      return Collectible(
        x: x,
        y: y,
        spriteIndex: objId - 21, // Same VSWAP math as decorations!
        mapId: objId,
        type: _getType(objId),
      );
    }
    return null;
  }
}
