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

import { shouldVoidArchivedMmaMatchup, type ArchivedMmaMatchup, type UfcFightRow } from '../mma-archive-validation';

const archive: ArchivedMmaMatchup = {
  home_team: 'Alex Pereira',
  away_team: 'Magomed Ankalaev',
};

describe('shouldVoidArchivedMmaMatchup', () => {
  it('does not void when the nearby card is missing entirely', () => {
    expect(shouldVoidArchivedMmaMatchup(archive, [])).toBe(false);
  });

  it('does not void when the exact matchup is on the nearby card', () => {
    const fights: UfcFightRow[] = [
      { fighter1Name: 'Magomed Ankalaev', fighter2Name: 'Alex Pereira' },
    ];

    expect(shouldVoidArchivedMmaMatchup(archive, fights)).toBe(false);
  });

  it('voids when neither fighter appears on the nearby card', () => {
    const fights: UfcFightRow[] = [
      { fighter1Name: 'Merab Dvalishvili', fighter2Name: 'Sean O\'Malley' },
    ];

    expect(shouldVoidArchivedMmaMatchup(archive, fights)).toBe(true);
  });

  it('does not void when a nearby card contains one fighter but not the archived opponent', () => {
    const fights: UfcFightRow[] = [
      { fighter1Name: 'Alex Pereira', fighter2Name: 'Jiri Prochazka' },
    ];

    expect(shouldVoidArchivedMmaMatchup(archive, fights)).toBe(false);
  });

  it('does not void when the archived opponent appears elsewhere on the card after a late swap', () => {
    const fights: UfcFightRow[] = [
      { fighter1Name: 'Alex Pereira', fighter2Name: 'Jiri Prochazka' },
      { fighter1Name: 'Magomed Ankalaev', fighter2Name: 'Jan Blachowicz' },
    ];

    expect(shouldVoidArchivedMmaMatchup(archive, fights)).toBe(false);
  });
});
