import { RacingRaceFactory } from './RacingRaceFactory';
import { RacingLeagueFactory } from './RacingLeagueFactory';
import { RacingTrackFactory } from './RacingTrackFactory';
import { RacingDriverFactory } from './RacingDriverFactory';
import { describe, expect, it } from 'vitest';

describe('RacingRaceFactory', () => {
  it('creates upcoming races in the future', () => {
    const baseDate = new Date('2024-01-01');
    const driverFactory = new RacingDriverFactory(10, baseDate, 'inmemory');
    const drivers = driverFactory.create();
    const leagueFactory = new RacingLeagueFactory(baseDate, drivers, 'inmemory');
    const leagues = leagueFactory.create();
    const trackFactory = new RacingTrackFactory();
    const tracks = trackFactory.create();

    const raceFactory = new RacingRaceFactory(baseDate, 'inmemory');
    const races = raceFactory.create(leagues, tracks);

    const scheduledRaces = races.filter((r) => r.status.toString() === 'scheduled');
    expect(scheduledRaces.length).toBeGreaterThan(0);

    const now = new Date();
    const upcomingRaces = scheduledRaces.filter((r) => r.scheduledAt > now);
    expect(upcomingRaces.length).toBeGreaterThan(0);
  });

  it('creates races with various statuses', () => {
    const baseDate = new Date('2024-01-01');
    const driverFactory = new RacingDriverFactory(10, baseDate, 'inmemory');
    const drivers = driverFactory.create();
    const leagueFactory = new RacingLeagueFactory(baseDate, drivers, 'inmemory');
    const leagues = leagueFactory.create();
    const trackFactory = new RacingTrackFactory();
    const tracks = trackFactory.create();

    const raceFactory = new RacingRaceFactory(baseDate, 'inmemory');
    const races = raceFactory.create(leagues, tracks);

    const statuses = new Set(races.map((r) => r.status.toString()));
    expect(statuses.has('scheduled')).toBe(true);
    expect(statuses.has('running')).toBe(true);
    expect(statuses.has('completed')).toBe(true);
    expect(statuses.has('cancelled')).toBe(true);
  });
});
