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

import { mapLorcanaCard } from '../../lib/card-import/lorcana-bulk.js';

describe('mapLorcanaCard', () => {
  it('maps Lorcana bulk API fields to cards table shape', () => {
    const mapped = mapLorcanaCard({
      Unique_ID: 'TFC-001',
      Name: 'Ariel - On Human Legs',
      Set_Name: 'The First Chapter',
      Set_ID: 'TFC',
      Card_Num: 1,
      Rarity: 'Uncommon',
      Cost: 4,
      Type: 'Character',
      Color: 'Amber, Sapphire',
      Classifications: 'Storyborn, Hero',
      Body_Text: 'Voiceless: This character cannot {e} to sing songs.',
      Strength: 3,
      Willpower: 4,
      Image: 'https://lorcana-api.com/images/ariel/on_human_legs/ariel-on_human_legs-large.png',
      Artist: 'Koni',
      Flavor_Text: '...',
      Lore: 2,
      Inkable: true,
      Abilities: 'Shift 3',
    });

    expect(mapped).toEqual({
      scryfallId: 'TFC-001',
      name: 'Ariel - On Human Legs',
      setName: 'The First Chapter',
      setCode: 'TFC',
      cardNumber: '1',
      rarity: 'Uncommon',
      manaCost: '4',
      cmc: 4,
      cardType: 'Character',
      colors: JSON.stringify(['Amber', 'Sapphire']),
      colorIdentity: JSON.stringify(['Amber', 'Sapphire']),
      oracleText: 'Voiceless: This character cannot {e} to sing songs.',
      power: '3',
      toughness: '4',
      imageUrl: 'https://lorcana-api.com/images/ariel/on_human_legs/ariel-on_human_legs-large.png',
      stockImageUrl: 'https://lorcana-api.com/images/ariel/on_human_legs/ariel-on_human_legs-large.png',
      flavorText: '...',
      artist: 'Koni',
      edhrecRank: 2,
      keywords: JSON.stringify(['Storyborn', 'Hero', 'Shift 3', 'Inkable']),
    });
  });

  it('omits Inkable keyword when card is not inkable', () => {
    const mapped = mapLorcanaCard({
      Unique_ID: 'ARI-001',
      Name: 'Rhino - Motivational Speaker',
      Set_Name: 'Archazia\'s Island',
      Set_ID: 'ARI',
      Card_Num: 1,
      Inkable: false,
      Classifications: 'Storyborn, Ally',
    });

    expect(JSON.parse(mapped.keywords)).toEqual(['Storyborn', 'Ally']);
  });
});
