import { Race } from '@core/racing/domain/entities/Race';
import { describe, expect, it } from 'vitest';
import { LeagueSchedulePresenter } from './LeagueSchedulePresenter';

describe('LeagueSchedulePresenter', () => {
  it('includes seasonId on the schedule DTO and serializes dates to ISO strings', () => {
    const presenter = new LeagueSchedulePresenter();

    const race = Race.create({
      id: 'race-1',
      leagueId: 'league-1',
      scheduledAt: new Date('2025-01-02T20:00:00Z'),
      track: 'Spa',
      car: 'GT3',
    });

    presenter.present({
      league: { id: 'league-1' },
      seasonId: 'season-1',
      published: false,
      races: [{ race }],
    } as never);

    const vm = presenter.getViewModel() as unknown as { seasonId: string, published: boolean, races: { id: string, name: string, date: string }[] };

    expect(vm).not.toBeNull();
    expect(vm.seasonId).toBe('season-1');
    expect(vm.published).toBe(false);

    expect(Array.isArray(vm.races)).toBe(true);
    expect(vm.races[0]!).toMatchObject({
      id: 'race-1',
      name: 'Spa - GT3',
      date: '2025-01-02T20:00:00.000Z',
    });

    // Guard: dates must be ISO strings (no Date objects)
    expect(typeof vm.races[0]!.date).toBe('string');
    expect(vm.races[0]!.date).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/);
  });
});