import Script, {
  ScriptEnvironment,
  ScriptPage,
  ScriptRunPhase,
} from './Script';
import { beforeEach, expect, it, jest } from '@jest/globals';
import LegacyScriptRunner from './LegacyScriptRunner';

interface FakeScriptOptions {
  id: string;
  priority: number;
}

class FakeScript extends Script {
  id: string;
  priority: number;
  page: ScriptPage.CommunityConsole;
  environment: ScriptEnvironment.ContentScript;
  runPhase: ScriptRunPhase.Main;

  constructor(options: FakeScriptOptions) {
    super();
    this.id = options.id;
    this.priority = options.priority;
  }

  execute() {}
}

const fakeScriptMock = jest
  .spyOn(FakeScript.prototype, 'execute')
  .mockImplementation(function() {
    return (this as FakeScript).id;
  });

beforeEach(() => {
  jest.clearAllMocks();
});

it('scripts run in the correct order based on priority', () => {
  const scriptsConfig = [
    {
      script: new FakeScript({
        id: '1',
        priority: 1,
      }),
      expectedRunPosition: 2,
    },
    {
      script: new FakeScript({
        id: '2',
        priority: 1000,
      }),
      expectedRunPosition: 3,
    },
    {
      script: new FakeScript({
        id: '3',
        priority: 0,
      }),
      expectedRunPosition: 1,
    },
    {
      script: new FakeScript({
        id: '4',
        priority: 2 ** 31,
      }),
      expectedRunPosition: 4,
    },
  ];

  const scriptRunner = new LegacyScriptRunner();
  scriptRunner.add(...scriptsConfig.map((config) => config.script));
  scriptRunner.run();

  expect(fakeScriptMock).toHaveBeenCalledTimes(scriptsConfig.length);
  for (const config of scriptsConfig) {
    expect(fakeScriptMock).toHaveNthReturnedWith(
      config.expectedRunPosition,
      config.script.id,
    );
  }
});
