package com.navinfo.outdoor.room;

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 java.util.List;

/**
 * 访问数据库操作的接口
 */
@Dao
public interface PoiDao {
    /**
     * 查询
     *
     * @return
     */
    @Query("SELECT * FROM poi")
    List<PoiEntity> getAllPoi();

    @Query("SELECT * FROM poi where taskStatus > 1 and type!=6")
    List<PoiEntity> getAllPoiByRecoder();

    @Query("SELECT * FROM poi where type=:type")
    List<PoiEntity> getAllPoiType(int type);


    @Query("SELECT * FROM poi WHERE (:taskStatus =-1 or taskStatus=:taskStatus1) and (:type=-1 or type=:type1) and (:isExclusive=-1 or isExclusive=:isExclusive1) ")
//    @Query("SELECT * FROM poi WHERE taskStatus=:taskStatus and type=:type and (:isExclusive=-1 or isExclusive=:isExclusive) ")
    List<PoiEntity> getAllTaskStatus(int taskStatus, int taskStatus1, int type, int type1, int isExclusive, int isExclusive1);


    @Query("SELECT * FROM poi where id=:id")
    PoiEntity getPoiEntity(String id);

    @Query("SELECT * FROM poi where taskId=:taskId")
    PoiEntity getTaskIdPoiEntity(int taskId);
    /**
     * 添加
     *
     * @param poiEntities
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertPoiEntity(PoiEntity... poiEntities);

    /**
     * 更新
     *
     * @param poiEntities
     */
    @Update
    void updatePoiEntity(PoiEntity... poiEntities);

    /**
     * 删除
     *
     * @param poiEntities
     */
    @Delete
    void deletePoiEntity(PoiEntity... poiEntities);

    /**
     * 删除
     *
     * @param poiEntities
     */
    @Delete
    void deleteAll(List<PoiEntity> poiEntities);

    /**
     * 根据条件删除
     *
     * @param taskStatus
     */
    @Query("DELETE  FROM poi where taskStatus=:taskStatus")
    void deleteFormName(int taskStatus);


    /**
     * 根据条件删除
     *
     * @param taskId
     */
    @Query("DELETE  FROM poi where taskId=:taskId")
    void deleteFormTaskID(int taskId);

    /**
     * 全部删除
     */
    @Query("DELETE FROM poi")
    void deleteAllPoiEntity();

    /**
     * 降序排列
     *
     * @return
     */
    @Query("SELECT * FROM poi ORDER BY ID DESC")
    List<PoiEntity> getAllPoiEntity();

    @Query("SELECT * FROM poi where userId = :userId")
    PoiEntity queryPoiEntity(int userId);

    @Query("DELETE FROM poi where userId = :userId")
    void deletePoiEntity(int userId);

}
