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

// Hoisted mocks: if the repository constructor still "news" these classes internally,
// the mocked constructors will be called and this test will fail.
vi.mock('../mappers/PointsTableJsonMapper', () => ({
  PointsTableJsonMapper: vi.fn(),
}));

vi.mock('../mappers/ChampionshipConfigJsonMapper', () => ({
  ChampionshipConfigJsonMapper: vi.fn(),
}));

vi.mock('../mappers/LeagueScoringConfigOrmMapper', () => ({
  LeagueScoringConfigOrmMapper: vi.fn(),
}));

describe('TypeOrmLeagueScoringConfigRepository', () => {
  it('constructor must not new sub-mappers internally (mapper graph must be injected)', async () => {
    const { PointsTableJsonMapper } = await import('../mappers/PointsTableJsonMapper');
    const { ChampionshipConfigJsonMapper } = await import('../mappers/ChampionshipConfigJsonMapper');
    const { LeagueScoringConfigOrmMapper } = await import('../mappers/LeagueScoringConfigOrmMapper');
    const { TypeOrmLeagueScoringConfigRepository } = await import('./TypeOrmLeagueScoringConfigRepository');

    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const dataSourceStub: any = { getRepository: vi.fn() };
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const injectedMapper: any = { toDomain: vi.fn(), toOrmEntity: vi.fn() };

    // If repo is still doing `new PointsTableJsonMapper()` etc. internally, the mocked constructors would be called.
    // eslint-disable-next-line @typescript-eslint/no-unsafe-call
    new (TypeOrmLeagueScoringConfigRepository as unknown as new (...args: unknown[]) => unknown)(
      dataSourceStub,
      injectedMapper,
    );

    expect(PointsTableJsonMapper).not.toHaveBeenCalled();
    expect(ChampionshipConfigJsonMapper).not.toHaveBeenCalled();
    expect(LeagueScoringConfigOrmMapper).not.toHaveBeenCalled();
  });
});