import { describe, it, expect } from 'vitest';
import { TAROT_DECK, SPREADS, CATEGORIES } from './cards';

describe('TAROT_DECK', () => {
  it('총 78장', () => {
    expect(TAROT_DECK).toHaveLength(78);
  });

  it('메이저 22장 + 마이너 56장', () => {
    const majors = TAROT_DECK.filter((c) => c.arcana === 'major');
    const minors = TAROT_DECK.filter((c) => c.arcana === 'minor');
    expect(majors).toHaveLength(22);
    expect(minors).toHaveLength(56);
  });

  it('slug 중복 없음', () => {
    const slugs = TAROT_DECK.map((c) => c.slug);
    expect(new Set(slugs).size).toBe(slugs.length);
  });

  it('모든 카드에 필수 필드 존재', () => {
    for (const c of TAROT_DECK) {
      expect(c.id).toBeTypeOf('number');
      expect(c.slug).toBeTruthy();
      expect(c.name).toBeTruthy();
      expect(c.arcana).toMatch(/^(major|minor)$/);
      expect(c.keywords).toBeInstanceOf(Array);
      expect(c.keywords.length).toBeGreaterThan(0);
      expect(c.reversedKeywords).toBeInstanceOf(Array);
      expect(c.reversedKeywords.length).toBeGreaterThan(0);
      expect(c.meaningUpright).toBeTruthy();
      expect(c.meaningReversed).toBeTruthy();
    }
  });

  it('마이너 카드는 suit, rank 필드를 가진다', () => {
    const minors = TAROT_DECK.filter((c) => c.arcana === 'minor');
    for (const c of minors) {
      expect(c.suit).toMatch(/^(wands|cups|swords|pentacles)$/);
      expect(c.rank).toBeTypeOf('number');
      expect(c.rank).toBeGreaterThanOrEqual(1);
      expect(c.rank).toBeLessThanOrEqual(14);
    }
  });
});

describe('SPREADS', () => {
  it('one_card / three_card 정의 존재', () => {
    expect(SPREADS.one_card.positions).toHaveLength(1);
    expect(SPREADS.three_card.positions).toHaveLength(3);
    expect(SPREADS.three_card.positions.map((p) => p.label)).toEqual(['과거', '현재', '미래']);
  });
});

describe('CATEGORIES', () => {
  it('6개 카테고리', () => {
    expect(CATEGORIES).toHaveLength(6);
    expect(CATEGORIES).toContain('연애');
    expect(CATEGORIES).toContain('일·커리어');
  });
});
