package com.example.myapplication.database.entities.composeui

import androidx.lifecycle.ViewModel
import com.example.myapplication.database.entities.model.Item
import com.example.myapplication.database.entities.model.ItemFromBike
import com.example.myapplication.database.entities.model.UserItemCrossRef
import com.example.myapplication.database.entities.repository.ItemRepository
import com.example.myapplication.database.entities.repository.UserItemRepository

class ItemListViewModel(
    private val itemRepository: ItemRepository,
    private val userItemRepository: UserItemRepository
) : ViewModel() {
    suspend fun deleteItem(item: ItemFromBike) {
        itemRepository.deleteItem(
            Item(
                uid = item.uid,
                dateTime = item.dateTime,
                weight = item.weight,
                maxCount = 0,
                bikeId = 0
            )
        )
    }

    suspend fun addItemInCart(userId: Int, itemId: Int, count: Int = 1) {
        try {
            userItemRepository.insertUserItem(UserItemCrossRef(userId, itemId, count))
        } catch (_: Exception) {

        }
    }
}