import { MediaReference } from '@core/domain/media/MediaReference';
import { describe, expect, it } from 'vitest';
import { RacingDriverFactory } from './RacingDriverFactory';
import { RacingLeagueFactory } from './RacingLeagueFactory';
import { RacingTeamFactory } from './RacingTeamFactory';

describe('RacingTeamFactory', () => {
  describe('createTeams', () => {
    it('should create teams with generated logoRef', () => {
      const baseDate = new Date();
      const driverFactory = new RacingDriverFactory(10, baseDate, 'inmemory');
      const leagueFactory = new RacingLeagueFactory(baseDate, driverFactory.create(), 'inmemory');
      const teamFactory = new RacingTeamFactory(baseDate, 'inmemory');
      
      const drivers = driverFactory.create();
      const leagues = leagueFactory.create();
      const teams = teamFactory.createTeams(drivers, leagues);
      
      expect(teams.length).toBeGreaterThan(0);
      
      teams.forEach(team => {
        expect(team.logoRef).toBeDefined();
        expect(team.logoRef instanceof MediaReference).toBe(true);
        expect(team.logoRef.type).toBe('generated');
        expect(team.logoRef.generationRequestId).toBe(`team-${team.id}`);
      });
    });

    it('should create deterministic teams', () => {
      const baseDate = new Date('2024-01-01');
      const driverFactory = new RacingDriverFactory(5, baseDate, 'inmemory');
      const leagueFactory = new RacingLeagueFactory(baseDate, driverFactory.create(), 'inmemory');
      
      const drivers = driverFactory.create();
      const leagues = leagueFactory.create();
      
      const teamFactory1 = new RacingTeamFactory(baseDate, 'inmemory');
      const teamFactory2 = new RacingTeamFactory(baseDate, 'inmemory');
      
      const teams1 = teamFactory1.createTeams(drivers, leagues);
      const teams2 = teamFactory2.createTeams(drivers, leagues);
      
      expect(teams1.length).toBe(teams2.length);
      
      for (let i = 0; i < teams1.length; i++) {
        const team1 = teams1[i]!;
        const team2 = teams2[i]!;
        expect(team1.id).toBe(team2.id);
        expect(team1.logoRef.equals(team2.logoRef)).toBe(true);
      }
    });
  });
});