import 'package:test/test.dart';
import 'package:wolf_3d_dart/src/registry/built_in/shareware_hud_module.dart';
import 'package:wolf_3d_dart/wolf_3d_data_types.dart';

void main() {
  group('SharewareHudModule', () {
    test('uses fixed WL1 offset in strict mode', () {
      final module = SharewareHudModule(useOriginalWl1Map: true);

      expect(module.resolve(HudKey.statusBar)?.vgaIndex, 95);
      expect(module.resolve(HudKey.digit0)?.vgaIndex, 108);
      expect(module.resolve(HudKey.digit9)?.vgaIndex, 117);
      expect(module.resolve(HudKey.faceHealthy)?.vgaIndex, 118);
      expect(module.resolve(HudKey.faceDead)?.vgaIndex, 139);
      expect(module.resolve(HudKey.pistolIcon)?.vgaIndex, 101);
      expect(module.resolve(HudKey.machineGunIcon)?.vgaIndex, 102);
      expect(module.resolve(HudKey.chainGunIcon)?.vgaIndex, 103);
    });

    test('detects shareware HUD offset from statusbar in heuristic mode', () {
      final module = SharewareHudModule();
      final sizes = List.generate(140, (_) => (width: 16, height: 16));
      sizes[95] = (width: 320, height: 40);

      module.initWithImageSizes(sizes);

      expect(module.resolve(HudKey.statusBar)?.vgaIndex, 95);
      expect(module.resolve(HudKey.digit0)?.vgaIndex, 108);
      expect(module.resolve(HudKey.faceHealthy)?.vgaIndex, 118);
    });
  });

  group('BuiltInAssetRegistryResolver HUD selection', () {
    test('uses shareware HUD mapping for exact WL1 identity', () {
      const resolver = BuiltInAssetRegistryResolver();
      final registry = resolver.resolve(
        const RegistrySelectionContext(
          gameVersion: GameVersion.shareware,
          dataVersion: DataVersion.version14Shareware,
        ),
      );

      expect(registry.hud.resolve(HudKey.statusBar)?.vgaIndex, 95);
      expect(registry.hud.resolve(HudKey.digit0)?.vgaIndex, 108);
      expect(registry.hud.resolve(HudKey.faceDead)?.vgaIndex, 139);
    });
  });
}
