package com.pixelized.shared.lwa.model.inventory.factory

import com.pixelized.shared.lwa.model.inventory.Inventory
import com.pixelized.shared.lwa.model.inventory.InventoryJson
import com.pixelized.shared.lwa.model.inventory.InventoryJsonV1
import com.pixelized.shared.lwa.protocol.rest.ApiPurseJson

class InventoryJsonFactory(
    private val v1: InventoryJsonFactoryV1,
) {
    fun convertFromJson(json: InventoryJson): Inventory {
        return when (json) {
            is InventoryJsonV1 -> v1.convertFromJson(json = json)
        }
    }

    fun convertToJson(inventory: Inventory): InventoryJson {
        return v1.convertToJson(inventory = inventory)
    }

    fun convertToApiPurse(
        characterSheetId: String,
        purse: Inventory.Purse,
    ): ApiPurseJson {
        return ApiPurseJson(
            characterSheetId = characterSheetId,
            gold = purse.gold,
            silver = purse.silver,
            copper = purse.copper,
        )
    }
}