package llc.arma.ble.data.db

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import llc.arma.ble.data.model.RotationEntity
import llc.arma.ble.data.model.WheelEntity

@Dao
interface RotationsDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun save(rotations: WheelEntity)

    @Query("select * from wheel where bleId = :serial")
    suspend fun getWheelBySerial(serial: String): WheelEntity?

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun save(rotations: List<RotationEntity>)

    @Query("delete from rotation where bleId = :serial")
    suspend fun deleteBySerial(serial: String)

    @Query("delete from rotation where bleId = :serial and date > :date")
    suspend fun deleteBySerialAndDateMoreThan(serial: String, date: Long)

    @Query("select * from rotation where bleId = :serial order by date asc")
    suspend fun getBySerialSortedByDate(serial: String): List<RotationEntity>

}