package com.gh.download.simple

import androidx.lifecycle.LiveData
import androidx.room.*
import io.reactivex.Single

@Dao
interface DownloadDao {

    @Query("select * from SimpleDownloadEntity where id = :id")
    fun getDownloadEntityById(id: String): SimpleDownloadEntity?

    @Query("select * from SimpleDownloadEntity")
    fun getAllDownloadEntity(): List<SimpleDownloadEntity>

    @Query("select * from SimpleDownloadEntity where status == 1")
    fun getAllDownloadingEntity(): List<SimpleDownloadEntity>

    @Query("select * from SimpleDownloadEntity where status == 3")
    fun getAllDownloadedEntity(): List<SimpleDownloadEntity>

    @Query("select * from SimpleDownloadEntity")
    fun getAllDownloadEntityLiveData(): LiveData<List<SimpleDownloadEntity>>

    @Query("select * from SimpleDownloadEntity")
    fun getAllDownloadEntitySingle(): Single<List<SimpleDownloadEntity>>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertDownloadEntity(entity: SimpleDownloadEntity)

    @Update(onConflict = OnConflictStrategy.REPLACE)
    fun updateDownloadEntity(entity: SimpleDownloadEntity)

    @Delete
    fun deleteDownloadEntity(entity: SimpleDownloadEntity)

}