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

import com.pixelized.shared.lwa.model.item.Item
import com.pixelized.shared.lwa.model.item.ItemJsonV1

class ItemJsonFactoryV1 {

    fun convertFromJson(json: ItemJsonV1): Item {
        return Item(
            id = json.id,
            metadata = Item.MetaData(
                label = json.metadata.name,
                description = json.metadata.description,
                image = json.metadata.image,
                thumbnail = json.metadata.thumbnail,
            ),
            options = Item.Options(
                stackable = json.options.stackable,
                equipable = json.options.equipable,
                consumable = json.options.consumable,
            ),
            tags = json.tags,
            alterations = json.alterations,
        )
    }

    fun convertToJson(item: Item): ItemJsonV1 {
        return ItemJsonV1(
            id = item.id,
            metadata = ItemJsonV1.ItemMetadataJsonV1(
                name = item.metadata.label,
                description = item.metadata.description,
                image = item.metadata.image?.takeIf { it.isNotBlank() },
                thumbnail = item.metadata.thumbnail?.takeIf { it.isNotBlank() },
            ),
            options = ItemJsonV1.ItemOptionJsonV1(
                stackable = item.options.stackable,
                equipable = item.options.equipable,
                consumable = item.options.consumable,
            ),
            tags = item.tags,
            alterations = item.alterations,
        )
    }
}