package com.pixelized.server.lwa.logics

import com.pixelized.server.lwa.services.character.CharacterSheetService
import com.pixelized.server.lwa.services.inventory.InventoryService

class ItemUsageLogic(
    private val characterSheetService: CharacterSheetService,
    private val inventoryService: InventoryService,
) {
    suspend fun consumeInventoryItem(
        characterSheetId: String,
        inventoryId: String,
    ): List<String> {
        val inventoryItem = inventoryService.getInventoryItem(
            characterSheetId = characterSheetId,
            inventoryId = inventoryId,
        )
        val item = inventoryService.getItem(
            itemId = inventoryItem.itemId,
        )
        // equip the item form the inventory
        inventoryService.consumeInventoryItem(
            characterSheetId = characterSheetId,
            inventoryId = inventoryId,
        )
        // if consume didn't throw then add the alteration to the character
        val alterations = item.alterations
        alterations.forEach { alterationId ->
            characterSheetService.updateAlteration(
                characterSheetId = characterSheetId,
                alterationId = alterationId,
                active = true,
            )
        }
        return alterations
    }
}