package com.rugvedsarika.shoplist.data.local.dao

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.rugvedsarika.shoplist.data.local.entities.ShoppingList

@Dao
interface ShoppingListDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertShoppingList(shoppingList: ShoppingList)

    @Delete
    suspend fun deleteShoppingList(shoppingList: ShoppingList)

    @androidx.room.Update
    suspend fun updateShoppingList(shoppingList: ShoppingList)

    @Query("SELECT * FROM shopping_lists ORDER BY createdAt DESC")
    fun getAllShoppingLists(): LiveData<List<ShoppingList>>

    @Query("SELECT * FROM shopping_lists WHERE name LIKE '%' || :query || '%' ORDER BY createdAt DESC")
    fun searchShoppingLists(query: String): LiveData<List<ShoppingList>>

    @Query("DELETE FROM shopping_lists")
    suspend fun deleteAllShoppingLists()
}
