package it.integry.integrywmsnative.core.data_store.db.dao;

import androidx.room.Dao;
import androidx.room.Query;

import java.util.List;

import io.reactivex.rxjava3.core.Flowable;
import it.integry.integrywmsnative.core.data_store.db.entity.BaseSyncDTO;
import it.integry.integrywmsnative.core.data_store.db.entity.InventarioRowRoomDTO;
import it.integry.integrywmsnative.core.data_store.db.interfaces.EntityDaoInterface;

@Dao
public interface InventarioRowDao extends EntityDaoInterface<InventarioRowRoomDTO> {

    @Query("SELECT * FROM " + InventarioRowRoomDTO.TABLE_NAME +
            " WHERE ((:toBeSync = 1 AND " + BaseSyncDTO.Columns.COLUMN_REMOTE_SYNC_DATE + " IS NULL) OR (:toBeSync = 0))")
    List<InventarioRowRoomDTO> selectAll(boolean toBeSync);


    @Query("SELECT * FROM " + InventarioRowRoomDTO.TABLE_NAME +
            " WHERE ((:toBeSync = 1 AND " + BaseSyncDTO.Columns.COLUMN_REMOTE_SYNC_DATE + " IS NULL) OR (:toBeSync = 0))" +
            "       AND " + InventarioRowRoomDTO.Columns.PARENT_ID + " = :parentId " +
            " ORDER BY " +
            "       CASE WHEN :reversed = 1 THEN " + BaseSyncDTO.Columns.ID + " END DESC," +
            "       CASE WHEN :reversed = 0 THEN " + BaseSyncDTO.Columns.ID + " END ASC")
    Flowable<List<InventarioRowRoomDTO>> selectAllFlowable(long parentId, boolean reversed, boolean toBeSync);
}
