package com.gestoreasy.database.dao

import androidx.room.*
import com.gestoreasy.database.entities.OrderItem

@Dao
interface OrderItemDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(item: OrderItem): Long
    
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertAll(items: List<OrderItem>)
    
    @Update
    suspend fun update(item: OrderItem)
    
    @Delete
    suspend fun delete(item: OrderItem)
    
    @Query("SELECT * FROM order_items WHERE id = :id")
    suspend fun getById(id: Long): OrderItem?
    
    @Query("SELECT * FROM order_items WHERE order_id = :orderId")
    suspend fun getByOrderId(orderId: Long): List<OrderItem>
    
    @Query("SELECT * FROM order_items ORDER BY created_at DESC")
    suspend fun getAll(): List<OrderItem>
    
    @Query("DELETE FROM order_items WHERE order_id = :orderId")
    suspend fun deleteByOrderId(orderId: Long)
}

