package com.adpro.pixelshow.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 MovieDao {

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    fun insertAll(movies: List<Movie>)

    @Update
    suspend fun update(movie: Movie)

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

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

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

    @Query("SELECT * FROM movies WHERE is_like = 1")
    fun queryLikeMovie(): LiveData<List<Movie>>

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

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

    @Query("SELECT * FROM movies")
    suspend fun getAllMovies(): List<Movie>
}