package com.gh.gamecenter.room.dao

import androidx.room.*
import com.gh.gamecenter.entity.SimulatorEntity
import com.gh.gamecenter.entity.SimulatorGameRecordEntity
import io.reactivex.Single

@Dao
interface SimulatorGameDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun addSimulatorGame(entity: SimulatorGameRecordEntity)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun addSimulatorGameList(entities: List<SimulatorGameRecordEntity>)

    @Query("select * from SimulatorGameRecordEntity")
    fun getAllSimulatorGame(): List<SimulatorGameRecordEntity>

    @Query("select * from SimulatorGameRecordEntity where simulatorType = :simulatorType and isDeleted = 0 order by isRecentlyPlayed desc limit :pageSize offset :offset")
    fun getSimulatorGameWithOffset(
        simulatorType: String,
        pageSize: Int,
        offset: Int
    ): Single<List<SimulatorGameRecordEntity>>

    @Query("select distinct simulator from SimulatorGameRecordEntity where isDeleted = 0 order by simulatorType desc")
    fun getSimulatorSingle(): Single<List<SimulatorEntity>>

    @Query("select distinct simulator from SimulatorGameRecordEntity where isDeleted = 0 order by simulatorType desc")
    fun getSimulatorList(): List<SimulatorEntity>

    @Query("delete from SimulatorGameRecordEntity where name = :name")
    fun deleteSimulatorGameByName(name: String)

    @Query("delete from SimulatorGameRecordEntity where id = :id")
    fun deleteSimulatorGameById(id: String)

    @Delete
    fun deleteSimulatorGameList(entities: List<SimulatorGameRecordEntity>)

    @Query("update SimulatorGameRecordEntity set isDeleted = 1 where name = :name")
    fun logicalDeleteSimulatorGame(name: String)

    @Query("select id from SimulatorGameRecordEntity where isDeleted = 1")
    fun getSimulatorGameByDeleted(): Single<List<String>>
}