import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import test from 'node:test';
import { fileURLToPath } from 'node:url';

const here = path.dirname(fileURLToPath(import.meta.url));
const publicRoot = path.resolve(here, '../../public');

void test('trap activation assets exist in public/ (mimic/pit/arrow/laser; explosion shared with effects)', () => {
  const video = path.join(publicRoot, 'vfx/mimic/tentacle-at-camera.webm');
  const sfx = path.join(publicRoot, 'mimic.mp3');
  assert.ok(fs.existsSync(video), `missing ${video}`);
  assert.ok(fs.existsSync(sfx), `missing ${sfx}`);
  assert.ok(fs.statSync(video).size > 10_000, 'mimic webm too small');
  assert.ok(fs.statSync(sfx).size > 1_000, 'mimic mp3 too small');

  const pitVideo = path.join(publicRoot, 'vfx/pit/infinity-portal.webm');
  const pitSfx = path.join(publicRoot, 'pit.mp3');
  assert.ok(fs.existsSync(pitVideo), `missing ${pitVideo}`);
  assert.ok(fs.existsSync(pitSfx), `missing ${pitSfx}`);
  assert.ok(fs.statSync(pitVideo).size > 10_000, 'pit webm too small');
  assert.ok(fs.statSync(pitSfx).size > 1_000, 'pit mp3 too small');

  const arrowVideo = path.join(publicRoot, 'vfx/arrow/arrows-grounding.webm');
  const arrowSfx = path.join(publicRoot, 'arrow.mp3');
  assert.ok(fs.existsSync(arrowVideo), `missing ${arrowVideo}`);
  assert.ok(fs.existsSync(arrowSfx), `missing ${arrowSfx}`);
  assert.ok(fs.statSync(arrowVideo).size > 10_000, 'arrow webm too small');
  assert.ok(fs.statSync(arrowSfx).size > 1_000, 'arrow mp3 too small');

  const laserVideo = path.join(publicRoot, 'vfx/laser/eye-lasers.webm');
  const laserSfx = path.join(publicRoot, 'laser.mp3');
  assert.ok(fs.existsSync(laserVideo), `missing ${laserVideo}`);
  assert.ok(fs.existsSync(laserSfx), `missing ${laserSfx}`);
  assert.ok(fs.statSync(laserVideo).size > 10_000, 'laser webm too small');
  assert.ok(fs.statSync(laserSfx).size > 1_000, 'laser mp3 too small');

  const exVideo = path.join(publicRoot, 'vfx/explosion/aerial-debris-smoke.webm');
  const exSfx = path.join(publicRoot, 'explosion.mp3');
  assert.ok(fs.existsSync(exVideo), `missing ${exVideo}`);
  assert.ok(fs.existsSync(exSfx), `missing ${exSfx}`);
});

void test('trapActivation registry covers mimic + pit + arrow + laser (explosion via effects)', () => {
  const src = fs.readFileSync(path.join(here, 'trapActivation.ts'), 'utf8');
  assert.match(src, /vfx\/mimic\/tentacle-at-camera\.webm/);
  assert.match(src, /mimic\.mp3/);
  assert.match(src, /vfx\/pit\/infinity-portal\.webm/);
  assert.match(src, /pit\.mp3/);
  assert.match(src, /vfx\/arrow\/arrows-grounding\.webm/);
  assert.match(src, /arrow\.mp3/);
  assert.match(src, /vfx\/laser\/eye-lasers\.webm/);
  assert.match(src, /laser\.mp3/);
  assert.match(src, /playTrapActivationSound/);
  assert.match(src, /isTrapMediaActivationKind/);
  assert.ok(!src.includes("videoPath: 'vfx/explosion"), 'explosion should not be local trap media');
});
