import { describe, expect, it } from 'vitest';

import { buildLeagueCoverageAuditReport, renderLeagueCoverageAuditMarkdown } from '../league-coverage-audit';

describe('league coverage audit', () => {
  it('reports WNBA as active end-to-end coverage instead of dormant support', () => {
    const report = buildLeagueCoverageAuditReport('2026-04-01T18:30:00.000Z');
    const wnba = report.leagues.find((league) => league.league === 'wnba');

    expect(wnba).toEqual(expect.objectContaining({
      league: 'wnba',
      seeded: true,
      sgoFeed: true,
      espnRoster: true,
      theOddsSport: true,
    }));
    expect(wnba?.registryStatCount).toBeGreaterThan(0);
    expect(wnba?.theOddsPropStatCount).toBeGreaterThan(0);
    expect(wnba?.endToEndReady).toBe(true);
  });

  it('flags Champions League as a roster-gap league', () => {
    const report = buildLeagueCoverageAuditReport('2026-04-01T18:30:00.000Z');
    const championsLeague = report.leagues.find((league) => league.league === 'champions_league');

    expect(championsLeague).toEqual(expect.objectContaining({
      league: 'champions_league',
      seeded: true,
      sgoFeed: true,
      espnRoster: false,
      theOddsSport: true,
    }));
    expect(championsLeague?.notes).toContain('registry-supported without ESPN roster mapping');
  });

  it('reports NCAAB as roster-backed once ESPN coverage exists', () => {
    const report = buildLeagueCoverageAuditReport('2026-04-01T18:30:00.000Z');
    const ncaab = report.leagues.find((league) => league.league === 'ncaab');

    expect(ncaab).toEqual(expect.objectContaining({
      league: 'ncaab',
      seeded: true,
      sgoFeed: true,
      espnRoster: true,
      theOddsSport: true,
      endToEndReady: true,
    }));
    expect(ncaab?.notes).not.toContain('registry-supported without ESPN roster mapping');
  });

  it('shows partial The Odds prop coverage where registry stats exceed mapped markets', () => {
    const report = buildLeagueCoverageAuditReport('2026-04-01T18:30:00.000Z');
    const epl = report.leagues.find((league) => league.league === 'epl');

    expect(epl?.registryStatCount).toBeGreaterThan(epl?.theOddsPropStatCount || 0);
    expect(epl?.notes).toContain('partial The Odds prop coverage (3/4)');
    expect(renderLeagueCoverageAuditMarkdown(report)).toContain('| epl |');
  });
});
