package com.zyzf.coffeepreorder.ui.cart

import androidx.lifecycle.ViewModel
import androidx.paging.PagingData
import com.zyzf.coffeepreorder.database.model.Coffee
import com.zyzf.coffeepreorder.database.repository.CartRepository
import kotlinx.coroutines.flow.Flow

class CartViewModel(
    private val cartRepository: CartRepository
) : ViewModel() {
    val coffeeListUiState: Flow<PagingData<Coffee>> = cartRepository.getAllInCart()

    fun getCountForCoffee(coffeeId: Int): Double {
        return cartRepository.getCountForCoffee(coffeeId)
    }

    suspend fun deleteCoffeeFromCart(coffee: Coffee) {
        cartRepository.deleteCoffee(coffee.uid, 1)
    }
}