package com.wallpaper.perfectwallpaper.room;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

@Dao
public interface ImageEntryDao {
    @Insert
    void insertAll(List<ImageEntry> imageEntry);

    @Update
    void update(ImageEntry imageEntry);

    @Query("SELECT * FROM ImageEntry LIMIT :limit OFFSET :offset")
    LiveData<List<ImageEntry>> getImageEntriesWithRange(int limit, int offset);

    @Query("SELECT * FROM ImageEntry ORDER BY RANDOM() LIMIT 20")
    LiveData<List<ImageEntry>> getRandomImageEntries();

    @Query("SELECT * FROM ImageEntry WHERE isLike = 1 ")
    LiveData<List<ImageEntry>> getAllFavoriteLive();

    @Query("SELECT * FROM ImageEntry WHERE id IN (SELECT MIN(id) FROM ImageEntry GROUP BY name)")
    LiveData<List<ImageEntry>> getFirstRecordOfEachName();

    @Query("SELECT * FROM ImageEntry WHERE name = :name")
    LiveData<List<ImageEntry>> getAllCategoryLive(String name);

    @Query("SELECT * FROM ImageEntry WHERE source = :ImagePath")
    ImageEntry getImageEntry(String ImagePath);

    @Query("SELECT * FROM ImageEntry WHERE original = :ImagePath")
    LiveData<ImageEntry> getImageEntryLive(String ImagePath);
}
