package com.example.shawarma.viewmodels

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import com.example.shawarma.data.models.ProductModel
import com.example.shawarma.data.repos.ProductRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class ProductsViewModel  @Inject constructor(
    private val productRepository: ProductRepository
) : ViewModel() {
    private val _products =  MutableLiveData<List<ProductModel>>()
    val products: LiveData<List<ProductModel>>
        get() = _products

    val productListUiState: Flow<PagingData<ProductModel>> = productRepository.getAllItemsPaged()

    fun deleteProduct(product: ProductModel) {
        viewModelScope.launch {
            productRepository.delete(product)
        }
    }


}