package com.ardrawing.ardrawingspace.room;

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

import java.util.List;

@Dao
public interface SpaceEntityDao {
    @Insert
    void insertAll(List<SpaceEntity> spaceEntityList);

    @Insert
    void insert(SpaceEntity spaceEntity);

    @Update
    void update(SpaceEntity spaceEntity);

    @Delete
    void delete(SpaceEntity spaceEntity);

    @Query("SELECT * FROM SpaceEntity WHERE imagePath LIKE 'png_' || :imagePath || '/%' AND imageType = 0 ORDER by id DESC")
    LiveData<List<SpaceEntity>> getEntityByImagePath(String imagePath);

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

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

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

    @Query("SELECT * FROM SpaceEntity WHERE favorite = 1 ")
    LiveData<List<SpaceEntity>> getFavorite();
}
