package com.paperapp.lenscape.element

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 ElementDao {

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    fun insertAll(element: List<Element>)

    @Update
    suspend fun update(element: Element)

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

    @Query("SELECT * FROM element WHERE classificationName=:name LIMIT 6 OFFSET 20")
    suspend fun queryCover(name: String): List<Element>

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

    @Query("SELECT * FROM element WHERE is_like = 1")
    fun queryLikeElement(): LiveData<List<Element>>

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

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

    @Query("SELECT * FROM element")
    suspend fun getAllElements(): List<Element>
}