// 商店商品配置（資料驅動 - 隨機刷新機制）

// 商品池 - 所有可能出現的商品及其出現機率
export const SHOP_POOL = [
    // 食物類 - 高機率
    {
        itemId: 'cookie',
        category: 'food',
        price: 10,
        appearChance: 0.8, // 80% 機率出現
        sellPrice: 5 // 賣出價格為購買價一半
    },
    {
        itemId: 'tuna_can',
        category: 'food',
        price: 30,
        appearChance: 0.6,
        sellPrice: 15
    },
    {
        itemId: 'premium_food',
        category: 'food',
        price: 50,
        appearChance: 0.3, // 30% 機率
        sellPrice: 25
    },

    // 藥品類 - 中機率
    {
        itemId: 'vitality_potion',
        category: 'medicine',
        price: 40,
        appearChance: 0.5,
        sellPrice: 20
    },

    // 裝備類 - 低機率
    {
        itemId: 'wooden_sword',
        category: 'equipment',
        price: 80,
        appearChance: 0.3,
        sellPrice: 40
    },
    {
        itemId: 'leather_armor',
        category: 'equipment',
        price: 100,
        appearChance: 0.25,
        sellPrice: 50
    },
    {
        itemId: 'magic_wand',
        category: 'equipment',
        price: 150,
        appearChance: 0.15, // 稀有
        sellPrice: 75
    },
    {
        itemId: 'hero_sword',
        category: 'equipment',
        price: 300,
        appearChance: 0.05, // 極稀有
        sellPrice: 150
    },

    // 玩具類
    {
        itemId: 'ball',
        category: 'toy',
        price: 20,
        appearChance: 0.6,
        sellPrice: 10
    },

    // 飾品類 - 稀有
    {
        itemId: 'lucky_charm',
        category: 'accessory',
        price: 150,
        appearChance: 0.2,
        sellPrice: 75
    }
]

// 商品分類
export const SHOP_CATEGORIES = {
    food: { name: '食物', icon: '🍖' },
    medicine: { name: '藥品', icon: '💊' },
    equipment: { name: '裝備', icon: '⚔️' },
    toy: { name: '玩具', icon: '🎾' },
    accessory: { name: '飾品', icon: '✨' }
}

// 生成隨機商店商品列表
export function generateShopItems() {
    const items = []
    for (const poolItem of SHOP_POOL) {
        // 按機率決定是否出現
        if (Math.random() < poolItem.appearChance) {
            items.push({
                ...poolItem,
                stock: -1 // 無限庫存
            })
        }
    }
    // 確保至少有3個商品
    if (items.length < 3) {
        // 隨機補充商品
        const remaining = SHOP_POOL.filter(p => !items.find(i => i.itemId === p.itemId))
        while (items.length < 3 && remaining.length > 0) {
            const randomIndex = Math.floor(Math.random() * remaining.length)
            items.push({
                ...remaining[randomIndex],
                stock: -1
            })
            remaining.splice(randomIndex, 1)
        }
    }
    return items
}
