package com.apps.pixwall.data

import android.graphics.Picture
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 PaperDao {

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    fun insertAll(papers: List<Paper>)

    @Update
    suspend fun update(paper: Paper)

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

    @Query("SELECT * FROM papers WHERE categoryName=:name LIMIT 4 OFFSET 6")
    suspend fun queryCover(name: String): List<Paper>

    @Query("SELECT * FROM papers WHERE categoryName=:name")
    suspend fun queryEachGenera(name: String): List<Paper>

    @Query("SELECT * FROM papers WHERE is_like = 1")
    fun queryLikePaper(): LiveData<List<Paper>>

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

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

    @Query("SELECT * FROM papers")
    suspend fun getAllPapers(): List<Paper>
}