package com.example.myapplication.DataBase;

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

import com.example.myapplication.model.ImageEntity;

import java.util.List;

@Dao
public interface ImageDao {
    @Insert
    void insert(ImageEntity image);

    @Query("SELECT * FROM images ORDER BY time DESC")
    List<ImageEntity> getAll();
    @Delete
    void delete(ImageEntity item);

    @Query("DELETE FROM images")
    void deleteAll();
    // 在ImageEntity类中添加查询方法
    @Query("SELECT * FROM images ORDER BY time DESC LIMIT 1")
    ImageEntity getLatestImage();


    // 定时间删除：根据 ID 删除特定记录
    @Query("DELETE FROM images WHERE time = :time")
    void deleteBytime(long time);
    @Query("SELECT * FROM images WHERE id = :id")
    ImageEntity getById(long id);
    @Update
    void update(ImageEntity latestImage);

    @Query("DELETE FROM images WHERE id IN (:ids)")
    void deleteByIds(List<Integer> ids);

    @Query("DELETE FROM images WHERE time BETWEEN :startTime AND :endTime")
    int deleteByTimeRange(long startTime, long endTime);
}
