import { describe, it, expect } from 'vitest';
import type { LeagueSummaryViewModel } from './LeagueSummaryViewModel';

describe('LeagueSummaryViewModel shape', () => {
  const createSummary = (overrides: Partial<LeagueSummaryViewModel> = {}): LeagueSummaryViewModel => ({
    id: 'league-1',
    name: 'Test League',
    description: 'A test league',
    ownerId: 'owner-1',
    createdAt: '2025-01-01T00:00:00Z',
    maxDrivers: 40,
    usedDriverSlots: 10,
    maxTeams: 10,
    usedTeamSlots: 4,
    structureSummary: 'Team-based sprint series',
    scoringPatternSummary: 'Top 15 points, 1 drop',
    timingSummary: 'Weekly, Wednesdays 20:00 UTC',
    scoring: {
      gameId: 'iracing',
      gameName: 'iRacing',
      primaryChampionshipType: 'driver',
      scoringPresetId: 'preset-1',
      scoringPresetName: 'Standard scoring',
      dropPolicySummary: '1 drop race',
      scoringPatternSummary: 'Top 15 receive points',
    },
    ...overrides,
  });

  it('accepts basic league summary structure', () => {
    const summary: LeagueSummaryViewModel = createSummary();

    expect(summary.id).toBe('league-1');
    expect(summary.name).toBe('Test League');
    expect(summary.structureSummary).toBeDefined();
    expect(summary.timingSummary).toBeDefined();
  });

  it('allows optional team and scoring fields to be omitted', () => {
    const summary: LeagueSummaryViewModel = createSummary({
      maxTeams: undefined,
      usedTeamSlots: undefined,
      scoring: undefined,
    });

    expect(summary.maxTeams).toBeUndefined();
    expect(summary.usedTeamSlots).toBeUndefined();
    expect(summary.scoring).toBeUndefined();
  });

  it('supports detailed scoring configuration when present', () => {
    const summary: LeagueSummaryViewModel = createSummary();

    expect(summary.scoring?.gameId).toBe('iracing');
    expect(summary.scoring?.primaryChampionshipType).toBe('driver');
    expect(summary.scoring?.dropPolicySummary).toContain('drop');
    expect(summary.scoring?.scoringPatternSummary).toContain('Top 15');
  });
});
