package com.example.myapplication.database.room.viewmodel.item

import com.example.myapplication.database.room.model.item.Item
import com.example.myapplication.database.room.model.item.ItemFromBike
import com.example.myapplication.database.room.model.user.UserItemCrossRef
import com.example.myapplication.database.room.repository.online.ItemRepository
import com.example.myapplication.database.room.repository.online.UserItemRepository
import com.example.myapplication.database.room.viewmodel.LoadingViewModel

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

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

        }
    }
}