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

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

import it.integry.integrywmsnative.core.data_store.db.entity.Ordine;
import it.integry.integrywmsnative.core.data_store.db.wrappers.OrdineWrapper;

@Dao
public interface OrdineDao {
    @Query("SELECT * from ordini ")
    List<Ordine> getAll();

    @Query("SELECT ordini.* from ordini where ordini.transmitted = 1")
    List<Ordine> getAllTrasnmitted();

    @Query("SELECT ordini.*, count(articolo_ordine_id) as countArticoli from ordini left join articoli_ordine ON ordini.ordine_id = articoli_ordine.id_ordine where ordini.transmitted = 0 and ((:codAlis is null and ordini.cod_alis is null) OR (ordini.cod_alis = :codAlis)) group by ordini.ordine_id")
    List<OrdineWrapper> getAllOpenOrdersByGriglia(String codAlis);

    @Insert
    Long insert(Ordine ordine);

    @Update
    void update(Ordine ordine);

    @Delete
    void delete(Ordine ordine);
}
