package com.pixelized.desktop.lwa.repository.item

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

class ItemRepository(
    private val itemStore: ItemStore,
) {
    fun itemFlow() = itemStore.items

    suspend fun updateItemFlow() {
        itemStore.updateItemFlow()
    }

    fun item(
        itemId: String?,
    ): Item? {
        return itemStore.items.value[itemId]
    }

    @Throws
    suspend fun updateItem(
        item: Item,
        create: Boolean,
    ) {
        itemStore.putItem(
            item = item,
            create = create,
        )
    }

    @Throws
    suspend fun deleteItem(
        itemId: String,
    ) {
        itemStore.deleteItem(
            itemId = itemId
        )
    }
}