package com.yono.messeripos.daos;

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 androidx.room.Update;

import com.yono.messeripos.models.ProductCartModels;

import java.util.List;

@Dao
public interface CartDaos {

    @Query("SELECT * FROM carts ORDER BY id DESC")
    public LiveData<List<ProductCartModels>> getCart();

    @Query("SELECT * FROM carts WHERE id_orders = :idCart")
    public LiveData<List<ProductCartModels>> getCartById(String idCart);

    @Query("SELECT * FROM carts WHERE id_orders = :orderId AND id_product_orders = :idOrders")
    public LiveData<List<ProductCartModels>> getCartByOrderId(String orderId, long idOrders);

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    public void insertProduct(ProductCartModels product);

    @Update(onConflict = OnConflictStrategy.IGNORE)
    public void updateProduct(ProductCartModels product);

    @Query("UPDATE carts SET quantity_orders = :qty WHERE id = :idCart")
    public void updateCart (long qty, long idCart);

    @Delete
    public void deleteProduct(ProductCartModels product);

}
