import 'package:wolf_3d_dart/src/data_types/enemy_animation.dart';
import 'package:wolf_3d_dart/src/data_types/sprite_frame_range.dart';
import 'package:wolf_3d_dart/src/registry/keys/entity_key.dart';
import 'package:wolf_3d_dart/src/registry/modules/entity_asset_module.dart';

/// Built-in entity asset module for all retail Wolf3D releases (v1.0, v1.1, v1.4).
///
/// Sprite ranges mirror the constants that were previously embedded in
/// [EnemyType] enum constructors, preserving the original id Software layout.
class RetailEntityModule extends EntityAssetModule {
  const RetailEntityModule();

  static final Map<EntityKey, EntityAssetDefinition> _defs = {
    EntityKey.guard: const EntityAssetDefinition(
      availableInShareware: true,
      animations: EnemyAnimationMap(
        idle: SpriteFrameRange(50, 57),
        walking: SpriteFrameRange(58, 89),
        dying: SpriteFrameRange(90, 93),
        pain: SpriteFrameRange(94, 94),
        dead: SpriteFrameRange(95, 95),
        attacking: SpriteFrameRange(96, 98),
      ),
    ),
    EntityKey.dog: const EntityAssetDefinition(
      availableInShareware: true,
      animations: EnemyAnimationMap(
        idle: SpriteFrameRange(99, 106),
        walking: SpriteFrameRange(99, 130),
        attacking: SpriteFrameRange(135, 137),
        pain: SpriteFrameRange(0, 0),
        dying: SpriteFrameRange(131, 133),
        dead: SpriteFrameRange(134, 134),
      ),
    ),
    EntityKey.ss: const EntityAssetDefinition(
      availableInShareware: true,
      animations: EnemyAnimationMap(
        idle: SpriteFrameRange(138, 145),
        walking: SpriteFrameRange(146, 177),
        attacking: SpriteFrameRange(184, 186),
        pain: SpriteFrameRange(182, 182),
        dying: SpriteFrameRange(178, 181),
        dead: SpriteFrameRange(183, 183),
      ),
    ),
    EntityKey.mutant: const EntityAssetDefinition(
      availableInShareware: false,
      animations: EnemyAnimationMap(
        idle: SpriteFrameRange(187, 194),
        walking: SpriteFrameRange(195, 226),
        attacking: SpriteFrameRange(234, 237),
        pain: SpriteFrameRange(231, 231),
        dying: SpriteFrameRange(227, 232, excluded: {231}),
        dead: SpriteFrameRange(233, 233),
      ),
    ),
    EntityKey.officer: const EntityAssetDefinition(
      availableInShareware: false,
      animations: EnemyAnimationMap(
        idle: SpriteFrameRange(238, 245),
        walking: SpriteFrameRange(246, 277),
        attacking: SpriteFrameRange(285, 287),
        pain: SpriteFrameRange(282, 282),
        dying: SpriteFrameRange(278, 283, excluded: {282}),
        dead: SpriteFrameRange(284, 284),
      ),
    ),
    // Bosses: no standard EnemyAnimationMap; sprite selection is handled
    // by custom update() logic in each boss class using baseSpriteIndex.
    EntityKey.hansGrosse: const EntityAssetDefinition(
      availableInShareware: false,
      baseSpriteIndex: 291,
    ),
  };

  @override
  EntityAssetDefinition? resolve(EntityKey key) => _defs[key];
}
