import { describe, it, expect } from 'vitest';
import { LeagueScoringPresetsViewModel } from './LeagueScoringPresetsViewModel';
import type { LeagueScoringPresetDTO } from '@/lib/types/generated/LeagueScoringPresetDTO';

const createPreset = (overrides: Partial<LeagueScoringPresetDTO> = {}): LeagueScoringPresetDTO => ({
  id: 'preset-1',
  name: 'Standard scoring',
  description: 'Top 15 get points',
  primaryChampionshipType: 'driver',
  sessionSummary: 'Sprint + Main',
  bonusSummary: 'None',
  dropPolicySummary: 'Best 6',
  ...overrides,
} as LeagueScoringPresetDTO);

describe('LeagueScoringPresetsViewModel', () => {
  it('maps presets array from DTO', () => {
    const presets = [createPreset(), createPreset({ id: 'preset-2', name: 'Alt scoring' })];

    const vm = new LeagueScoringPresetsViewModel({ presets });

    expect(vm.presets).toBe(presets);
    expect(vm.totalCount).toBe(2);
  });

  it('uses explicit totalCount when provided', () => {
    const presets = [createPreset(), createPreset()];

    const vm = new LeagueScoringPresetsViewModel({ presets, totalCount: 10 });

    expect(vm.presets).toBe(presets);
    expect(vm.totalCount).toBe(10);
  });

  it('handles empty presets array', () => {
    const vm = new LeagueScoringPresetsViewModel({ presets: [] });

    expect(vm.presets).toEqual([]);
    expect(vm.totalCount).toBe(0);
  });
});
