package melody.offline.music.database

import androidx.room.*
import melody.offline.music.bean.OfflineBean

@Dao
interface OfflineDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertOfflineBean(bean: OfflineBean)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertOfflineBeans(beans: List<OfflineBean>)

    @Query("SELECT * FROM OfflineBean")
    suspend fun getAllOfflineBeans(): List<OfflineBean>

    @Delete
    suspend fun deleteOfflineBean(bean: OfflineBean)

    @Query("DELETE FROM OfflineBean")
    suspend fun deleteAllOfflineBean()

    @Update
    suspend fun updateOfflineBean(bean: OfflineBean)

    @Query("SELECT * FROM OfflineBean WHERE videoId = :id LIMIT 1")
    suspend fun getOfflineBeanByID(id: String): OfflineBean?

    @Query("SELECT * FROM OfflineBean WHERE isOffline = 1")
    suspend fun getOfflineBeanByIsOffline(): List<OfflineBean>

}
