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

import {
  filterMissingMtgSets,
  filterMissingPokemonSets,
} from '../../lib/card-import/discover.js';

describe('filterMissingMtgSets', () => {
  const now = new Date('2026-05-27T12:00:00.000Z');

  it('returns released paper sets missing from the catalog, newest first', () => {
    const known = new Set(['lea']);
    const missing = filterMissingMtgSets(
      [
        { code: 'lea', name: 'Alpha', released_at: '1993-08-05', set_type: 'core', digital: false },
        { code: 'fin', name: 'Final Fantasy', released_at: '2026-05-01', set_type: 'expansion', digital: false },
        { code: 'dsk', name: 'Duskmourn', released_at: '2024-09-27', set_type: 'expansion', digital: false },
        { code: 'tlea', name: 'Alpha Tokens', released_at: '1993-08-05', set_type: 'token', digital: false },
        { code: 'mh3', name: 'Modern Horizons 3', released_at: '2027-01-01', set_type: 'expansion', digital: false },
      ],
      known,
      now
    );

    expect(missing).toEqual([
      {
        code: 'fin',
        name: 'Final Fantasy',
        releasedAt: '2026-05-01',
      },
      {
        code: 'dsk',
        name: 'Duskmourn',
        releasedAt: '2024-09-27',
      },
    ]);
  });
});

describe('filterMissingPokemonSets', () => {
  it('returns sets whose ids are not in the catalog, newest first', () => {
    const known = new Set(['sv1']);
    const missing = filterMissingPokemonSets(
      [
        { id: 'sv1', name: 'Scarlet & Violet', releaseDate: '2023-03-31' },
        { id: 'sv2', name: 'Paldea Evolved', releaseDate: '2023-06-09' },
        { id: 'sv3', name: 'Obsidian Flames', releaseDate: '2023-08-11' },
      ],
      known
    );

    expect(missing).toEqual([
      {
        id: 'sv3',
        name: 'Obsidian Flames',
        releasedAt: '2023-08-11',
      },
      {
        id: 'sv2',
        name: 'Paldea Evolved',
        releasedAt: '2023-06-09',
      },
    ]);
  });
});
