// 測試所有事件
async function testAllEvents() {
    if (!eventSystem) {
        console.log('❌ 系統尚未初始化')
        return
    }

    const events = await apiService.getEvents()

    console.log('\n' + '='.repeat(60))
    console.log('🧪 開始測試所有事件...')
    console.log('='.repeat(60))

    for (const event of events) {
        console.log(`\n▶️ 測試事件: ${event.id} (${event.type})`)
        console.log('   狀態 BEFORE:')
        const stateBefore = petSystem.getState()
        console.log(`   飢餓: ${stateBefore.hunger.toFixed(1)} | 快樂: ${stateBefore.happiness.toFixed(1)} | 健康: ${stateBefore.health.toFixed(1)}`)

        // 觸發事件
        await triggerEvent(event.id)

        // 等待更新
        await new Promise(resolve => setTimeout(resolve, 100))

        console.log('   狀態 AFTER:')
        const stateAfter = petSystem.getState()
        console.log(`   飢餓: ${stateAfter.hunger.toFixed(1)} | 快樂: ${stateAfter.happiness.toFixed(1)} | 健康: ${stateAfter.health.toFixed(1)}`)

        console.log('   ─'.repeat(30))
    }

    console.log('\n' + '='.repeat(60))
    console.log('✅ 所有事件測試完成')
    console.log('='.repeat(60) + '\n')

    showStatus()
}

// 測試單個事件（詳細版）
async function testEvent(eventId) {
    if (!eventSystem) {
        console.log('❌ 系統尚未初始化')
        return
    }

    const events = await apiService.getEvents()
    const event = events.find(e => e.id === eventId)

    if (!event) {
        console.log(`❌ 找不到事件: ${eventId}`)
        console.log('💡 使用 listEvents() 查看所有事件')
        return
    }

    console.log('\n' + '='.repeat(60))
    console.log(`🧪 測試事件: ${event.id}`)
    console.log('='.repeat(60))
    console.log(`類型: ${event.type}`)
    console.log(`效果數量: ${event.effects.length}`)
    console.log('')

    // 顯示效果
    event.effects.forEach((eff, i) => {
        console.log(`效果 ${i + 1}: ${eff.type}`)
        if (eff.payload) {
            console.log('  payload:', eff.payload)
        }
    })

    console.log('\n觸發前狀態:')
    showStatus()

    console.log('\n▶️ 觸發事件...\n')
    await triggerEvent(eventId)

    await new Promise(resolve => setTimeout(resolve, 100))

    console.log('\n觸發後狀態:')
    showStatus()

    console.log('='.repeat(60) + '\n')
}

window.testAllEvents = testAllEvents
window.testEvent = testEvent
