// src/testCommands.js
const CommandHandler = require('./commands/CommandHandler');
const PlayerService = require('./services/PlayerService');

// Mock Discord interaction
class MockInteraction {
    constructor(commandName, options = {}) {
        this.commandName = commandName;
        this.deferred = false;
        this.replied = false;
        this.options = {
            getString: (name) => options[name]
        };
    }

    async deferReply() {
        this.deferred = true;
        console.log('Interaction deferred');
    }

    async reply(content) {
        this.replied = true;
        console.log('Reply sent:', content);
    }

    async editReply(content) {
        console.log('Edit reply:', content);
        if (content.embeds) {
            console.log('\nEmbed fields:');
            content.embeds.forEach(embed => {
                console.log('Title:', embed.data.title);
                console.log('Description:', embed.data.description);
                if (embed.data.fields) {
                    embed.data.fields.forEach(field => {
                        console.log(`${field.name}: ${field.value}`);
                    });
                }
            });
        }
    }
}

async function testCommands() {
    console.log('Testing commands...\n');

    const playerService = new PlayerService();
    const commandHandler = new CommandHandler(playerService);

    // Test finduser command
    console.log('Testing /finduser command...');
    const findUserInteraction = new MockInteraction('finduser', {
        username: 'uthcowboys'
    });
    await commandHandler.handleFindUser(findUserInteraction);

    // Test matchhistory command
    console.log('\nTesting /matchhistory command...');
    const matchHistoryInteraction = new MockInteraction('matchhistory', {
        username: 'uthcowboys'
    });
    await commandHandler.handleMatchHistory(matchHistoryInteraction);
}

// Run tests
testCommands().then(() => {
    console.log('\nCommand tests completed.');
}).catch(error => {
    console.error('Command tests failed:', error);
});