/* eslint-disable @typescript-eslint/no-explicit-any */
import { LeagueConfigPresenter } from './LeagueConfigPresenter';

describe('LeagueConfigPresenter', () => {
  const createFullConfig = (overrides: Partial<any> = {}): unknown => {
    const base: unknown = {
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      league: {
        id: 'league-1',
        name: 'Test League',
        description: 'Desc',
        ownerId: 'owner-1',
        settings: { pointsSystem: 'custom' },
        createdAt: new Date(),
      } as never,
      activeSeason: {
        id: 'season-1',
        leagueId: 'league-1',
        gameId: 'iracing',
        name: 'Season 1',
        status: 'planned',
        schedule: {
          startDate: new Date('2025-01-05T19:00:00Z'),
          timeOfDay: { hour: 20, minute: 0 } as never,
        } as never,
        dropPolicy: { strategy: 'bestNResults', n: 3 } as never,
        stewardingConfig: {
          decisionMode: 'steward_vote',
          requiredVotes: 3,
          requireDefense: true,
          defenseTimeLimit: 24,
          voteTimeLimit: 24,
          protestDeadlineHours: 48,
          stewardingClosesHours: 72,
          notifyAccusedOnProtest: true,
          notifyOnVoteRequired: true,
        } as never,
      } as never,
      scoringConfig: {
        id: 'scoring-1',
        seasonId: 'season-1',
        championships: [
          {
            id: 'champ-1',
            name: 'Drivers',
            type: 'driver' as never,
            sessionTypes: ['race'] as never,
            pointsTableBySessionType: {
              race: {
                getPointsForPosition: (pos: number) => (pos === 1 ? 25 : 0),
              } as never,
            },
            dropScorePolicy: { strategy: 'bestNResults', count: 3 } as never,
          },
        ],
      } as never,
      game: undefined,
      ...overrides,
    };

    return base;
  };

  it('maps league config into form model with scoring and timings', () => {
    const presenter = new LeagueConfigPresenter();
    const fullConfig = createFullConfig();

    presenter.present({ config: fullConfig } as never);
    const vm = presenter.getViewModel()!;

    expect(vm).not.toBeNull();
    expect(vm!.leagueId).toBe('league-1');
    expect(vm!.basics.name).toBe('Test League');
    expect(vm!.scoring.type).toBe('custom');
    expect(vm!.scoring.points).toBe(25);
    expect(vm!.championships.length).toBe(1);
    expect(vm!.timings.raceTimeHour).toBe(20);
    expect(vm!.timings.raceTimeMinute).toBe(0);
    expect(vm!.dropPolicy.strategy).toBe('worst_n');
    expect(vm!.dropPolicy.n).toBe(3);
    expect(vm!.stewarding.decisionMode).toBe('committee_vote');
  });
});
