package com.example.shawarma.data.interfaces.dao

import androidx.paging.PagingSource
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.example.shawarma.data.models.ProductModel
import kotlinx.coroutines.flow.Flow
@Dao
interface ProductDao {
    @Insert
    suspend fun insert(product: ProductModel)

    @Update
    suspend fun update(product: ProductModel)

    @Delete()
    suspend fun delete(product: ProductModel)

    @Query("select * from products where products.product_old_price is null")
    fun getAll() : Flow<List<ProductModel>>

    @Query("select * from products where products.product_old_price is not null")
    fun getDiscounts() : Flow<List<ProductModel>>

    @Query("select * from products")
    fun getItems() : Flow<List<ProductModel>>

    @Query("select * from products where products.id = :id")
    fun getById(id: Int): Flow<ProductModel>

    @Query("select * from products where products.product_old_price is null")
    fun getPaged(): PagingSource<Int, ProductModel>

    @Query("select * from products where products.product_old_price is not null")
    fun getPagedDiscounts(): PagingSource<Int, ProductModel>

    @Query("select * from products")
    fun getPagedItems(): PagingSource<Int, ProductModel>
}