import { readFileSync } from 'node:fs';
import { join } from 'node:path';

import { describe, expect, it } from 'vitest';

function readSource(workspaceRelativePath: string): string {
  const absolutePath = join(process.cwd(), workspaceRelativePath);
  return readFileSync(absolutePath, 'utf8');
}

describe('events v2 legacy removal guard', () => {
  it('keeps the active session loop free of legacy event polling calls', () => {
    const playerSessionSource = readSource('src/game/PlayerSession.ts');

    expect(playerSessionSource.includes('checkDilemmas(this.player)')).toBe(false);
    expect(playerSessionSource.includes('checkEvents(this.player')).toBe(false);
    expect(playerSessionSource.includes('checkTutorialEvents(this.player')).toBe(false);
    expect(playerSessionSource.includes('Object.entries(allEvents)')).toBe(false);
  });

  it('marks legacy runtime modules as deprecated compatibility paths', () => {
    const statsManagerSource = readSource('src/stats/stats_manager.ts');
    const eventRegistrySource = readSource('src/game/engine/EventRegistry.ts');
    const eventsIndexSource = readSource('src/events/index.ts');
    const playerModelSource = readSource('src/models/Player.ts');

    expect(statsManagerSource.includes('@deprecated Active runtime uses events/v2 engine')).toBe(true);
    expect(eventRegistrySource.includes('@deprecated Active event runtime is events/v2 registry + engine.')).toBe(true);
    expect(eventsIndexSource.includes('@deprecated Active runtime prompts and resolutions come from events/v2 catalog.')).toBe(true);
    expect(playerModelSource.includes('Legacy v1 dilemmas (deprecated, inactive runtime path)')).toBe(true);
  });
});
