import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
import 'package:wolf_3d_entities/src/entities/collectible.dart';
import 'package:wolf_3d_entities/src/entities/decorations/dead_aardwolf.dart';
import 'package:wolf_3d_entities/src/entities/decorations/dead_guard.dart';
import 'package:wolf_3d_entities/src/entities/decorative.dart';
import 'package:wolf_3d_entities/src/entities/enemies/bosses/hans_grosse.dart';
import 'package:wolf_3d_entities/src/entities/enemies/enemy.dart';
import 'package:wolf_3d_entities/src/entity.dart';

typedef EntitySpawner =
    Entity? Function(
      int objId,
      double x,
      double y,
      Difficulty difficulty, {
      bool isSharewareMode,
    });

abstract class EntityRegistry {
  static final List<EntitySpawner> _spawners = [
    // Special
    DeadGuard.trySpawn,
    DeadAardwolf.trySpawn,

    // Bosses
    HansGrosse.trySpawn,

    // Decorations
    Decorative.trySpawn,

    // Enemies need to try to spawn first
    Enemy.spawn,

    // Collectables
    Collectible.trySpawn,
  ];

  static Entity? spawn(
    int objId,
    double x,
    double y,
    Difficulty difficulty,
    int maxSprites, {
    bool isSharewareMode = false,
  }) {
    if (objId == 0) return null;

    for (final spawner in _spawners) {
      Entity? entity = spawner(
        objId,
        x,
        y,
        difficulty,
        isSharewareMode: isSharewareMode,
      );
      if (entity != null) return entity;
    }
    return null;
  }
}
