package com.ardraw.ardrawinggallery.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 ArDataDao {
    @Insert
    void insertAll(List<ArData> ArData);

    @Insert
    void insert(ArData ArData);

    @Update
    void update(ArData ArData);

    @Query("SELECT * FROM ArData WHERE imagePath LIKE 'png_' || :name || '/%' AND imageType = 0")
    LiveData<List<ArData>> getListByName(String name);

    @Query("SELECT * FROM ArData WHERE id IN ( SELECT MIN(id) FROM ArData WHERE imageType = 0 GROUP BY SUBSTR(ImagePath, 1, INSTR(ImagePath, '/') - 1))")
    LiveData<List<ArData>> getFirst();

    @Query("SELECT * FROM ArData WHERE imagePath LIKE :name || '%' AND imageType = 0 LIMIT 20 OFFSET :index")
    LiveData<List<ArData>> getImageByIndex(String name, int index);

    @Query("SELECT * FROM ArData WHERE imageType = 1 ")
    LiveData<List<ArData>> getAllImportLive();

    @Query("SELECT * FROM ArData WHERE imageType = 1 ")
    List<ArData> getAllImport();

    @Query("SELECT * FROM ArData WHERE isFavorite = 1 ")
    LiveData<List<ArData>> getAllFavorite();

}
