package com.example.chemical.ui.plan.room.dao;

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.example.chemical.ui.plan.room.bean.locker.CabinetLayerSelect;

import java.util.List;

@Dao
public interface HxpLayerDAO {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(CabinetLayerSelect layerSelect);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertAll(List<CabinetLayerSelect> layerSelects);

    @Query("SELECT * FROM cabinetlayerselect")
    List<CabinetLayerSelect> getAll();

    @Query("SELECT * FROM cabinetlayerselect WHERE layer = :layer AND cabinetId =:cabinetId AND doorId =:doorId")
    CabinetLayerSelect getById(long cabinetId, long doorId, long layer);

    @Query("UPDATE cabinetlayerselect SET isChange = CASE WHEN (layer = :layer AND cabinetId =:cabinetId AND doorId =:doorId) THEN 1 ELSE 0 END")
    void change(long cabinetId, long doorId, long layer);

    @Query("SELECT * FROM cabinetlayerselect WHERE isChange = 1")
    CabinetLayerSelect getChanged();

    @Query("SELECT * FROM cabinetlayerselect WHERE isChange = 1 AND cabinetId =:cabinetId")
    CabinetLayerSelect getCabinetChanged(long cabinetId);

    @Update
    void update(CabinetLayerSelect cabinetlayerselect);

    @Delete
    void delete(CabinetLayerSelect cabinetlayerselect);

    @Query("DELETE FROM cabinetlayerselect")
    void deleteAll();

}
