package com.design.zenspace.entity

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

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    fun insertAll(feature: List<Feature>)

    @Update
    suspend fun update(feature: Feature)

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

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

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

    @Query("SELECT * FROM feature WHERE is_like = 1")
    fun queryLikeFeature(): LiveData<List<Feature>>

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

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

    @Query("SELECT * FROM feature")
    suspend fun getAllFeatures(): List<Feature>
}