package com.rugvedsarika.shoplist.data.repository

import androidx.lifecycle.LiveData
import com.rugvedsarika.shoplist.data.local.dao.ShoppingItemDao
import com.rugvedsarika.shoplist.data.local.dao.ShoppingListDao
import com.rugvedsarika.shoplist.data.local.entities.ShoppingItem
import com.rugvedsarika.shoplist.data.local.entities.ShoppingList

class ShopRepository(
    private val shoppingListDao: ShoppingListDao,
    private val shoppingItemDao: ShoppingItemDao
) {

    // Shopping List Operations
    val allShoppingLists: LiveData<List<ShoppingList>> = shoppingListDao.getAllShoppingLists()

    fun searchShoppingLists(query: String): LiveData<List<ShoppingList>> {
        return shoppingListDao.searchShoppingLists(query)
    }

    suspend fun insertShoppingList(shoppingList: ShoppingList) {
        shoppingListDao.insertShoppingList(shoppingList)
    }

    suspend fun updateShoppingList(shoppingList: ShoppingList) {
        shoppingListDao.updateShoppingList(shoppingList)
    }

    suspend fun deleteShoppingList(shoppingList: ShoppingList) {
        shoppingListDao.deleteShoppingList(shoppingList)
    }

    suspend fun deleteAllShoppingLists() {
        shoppingListDao.deleteAllShoppingLists()
    }

    // Shopping Item Operations
    fun getItemsByListId(listId: Int): LiveData<List<ShoppingItem>> {
        return shoppingItemDao.getItemsByListId(listId)
    }

    fun searchItems(listId: Int, query: String): LiveData<List<ShoppingItem>> {
        return shoppingItemDao.searchItems(listId, query)
    }

    suspend fun insertShoppingItem(item: ShoppingItem) {
        shoppingItemDao.insertShoppingItem(item)
    }

    suspend fun updateShoppingItem(item: ShoppingItem) {
        shoppingItemDao.updateShoppingItem(item)
    }

    suspend fun deleteShoppingItem(item: ShoppingItem) {
        shoppingItemDao.deleteShoppingItem(item)
    }

    suspend fun deleteItemsByListId(listId: Int) {
        shoppingItemDao.deleteItemsByListId(listId)
    }
    
    suspend fun deleteAllShoppingItems() {
        shoppingItemDao.deleteAllShoppingItems()
    }
}
