package com.design.wallpapergallery.data

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

@Dao
interface PhotoDao {

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    fun insertAll(photos: List<Photo>)

    @Update
    suspend fun update(photo: Photo)

    @Query("SELECT * FROM photos WHERE imId=:imId")
    suspend fun getById(imId: String): Photo?

    @Query("SELECT * FROM photos WHERE classificationName=:name LIMIT 4 OFFSET 20")
    suspend fun queryCover(name: String): List<Photo>

    @Query("SELECT * FROM photos WHERE classificationName=:name")
    suspend fun queryEachGenera(name: String): List<Photo>

    @Query("SELECT * FROM photos WHERE is_like = 1")
    fun queryLikePhoto(): LiveData<List<Photo>>

    @Query("SELECT * FROM photos WHERE description LIKE '%'||:name||'%'")
    suspend fun search(name: String): List<Photo>

    @Query("SELECT * FROM photos WHERE imId = :imId AND is_like = 1")
    suspend fun queryIsLike(imId: String): Photo?

    @Query("SELECT * FROM photos")
    suspend fun getAllPhotos(): List<Photo>
}