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

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.OrderModel
import com.example.shawarma.data.models.OrderWithProducts
import kotlinx.coroutines.flow.Flow
@Dao
interface OrderDao {
    @Insert
    suspend fun insert(order: OrderModel) : Long
    @Update
    suspend fun update(order: OrderModel)
    @Delete
    suspend fun delete(order: OrderModel)
    @Query("select * from orders")
    fun getAll(): Flow<List<OrderWithProducts>>
    @Query("select * from orders where orders.id =:id")
    fun getById(id: Int): Flow<List<OrderWithProducts>>
    @Query("select * from orders where orders.user_id =:userId")
    fun getByUserId(userId: Int): Flow<List<OrderWithProducts>>
    @Query("select * from orders where orders.user_id =:userId and orders.order_status = 'Неоплачено'")
    fun getUnpaidByUser(userId: Int) : Flow<OrderWithProducts>
    @Query("select * from orders where orders.user_id =:userId and (orders.order_status = 'Готовится' or orders.order_status = 'Готово')")
    fun getPaidByUser(userId: Int) : Flow<List<OrderWithProducts>>
}