package com.ardraw.ardrawingflow.data.database.dao;

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 com.ardraw.ardrawingflow.data.database.entity.FlowData;

import java.util.List;

@Dao
public interface FlowDataDao {
    @Insert
    void insertAll(List<FlowData> flowDataList);

    @Insert
    void insert(FlowData flowData);

    @Update
    void update(FlowData flowData);

    @Delete
    void delete(FlowData flowData);

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

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

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

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

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

}
