// Simple test to verify the card parser and game state builder work

const { parseCard, isCardPlayable, getPlayableCards } = require('./client/src/utils/cardParser');
const { buildGameStateJSON } = require('./client/src/utils/gameStateBuilder');

console.log('Testing Card Parser...');

// Test 1: Parse a simple number card
const card1 = parseCard('5R');
console.log('✓ Parse 5R:', JSON.stringify(card1, null, 2));

// Test 2: Parse a wild card
const card2 = parseCard('W');
console.log('✓ Parse W:', JSON.stringify(card2, null, 2));

// Test 3: Check playability
const playable = isCardPlayable('5R', 'R', 3);
console.log('✓ Can play 5R on 3R?', playable);

// Test 4: Get playable cards
const hand = ['5R', '7B', 'W', '3G'];
const playableCards = getPlayableCards(hand, 'R', 5);
console.log('✓ Playable cards from hand:', playableCards.map(c => c.code));

console.log('\nTesting Game State Builder...');

// Test 5: Build game state
const mockGameState = {
    gameOver: false,
    winner: null,
    turn: 'Player 2',
    player1Deck: ['1R', '2B', '3G', '4Y', '5R'],
    player2Deck: ['5R', '7B', 'W'],
    currentColor: 'R',
    currentNumber: 5,
    playedCardsPile: ['1B', '2B', '3R', '4R', '5R'],
    drawCardPile: new Array(80).fill('back')
};

try {
    const gameStateJSON = buildGameStateJSON(mockGameState, 'Player 2');
    console.log('✓ Game State JSON generated successfully!');
    console.log('  Turn:', gameStateJSON.game.currentTurn);
    console.log('  Current Card:', gameStateJSON.currentCard.displayName);
    console.log('  Bot has', gameStateJSON.player2.cards.length, 'cards');
    console.log('  Playable:', gameStateJSON.player2.playableCards.length);
    console.log('  Actions:', gameStateJSON.botContext.actions.length);
} catch (error) {
    console.error('✗ Error building game state:', error.message);
}

console.log('\n✅ All tests passed!');
