package com.za.offline

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update

@Dao
interface OfflineDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertOfflineTask(offlineUpdateTaskBean: OfflineUpdateTaskBean)

    @Query("select * from offline_update_task_bean where taskId =:taskId")
    fun getOfflineTaskFromTaskId(taskId: Int): List<OfflineUpdateTaskBean>?

    @Query("select * from offline_update_task_bean where primaryId =:primaryId")
    fun getOfflineTaskFromPrimaryId(primaryId: Int): OfflineUpdateTaskBean?


    @Query("select * from offline_update_task_bean where taskId =:taskId and offlineType=1")
    fun getRecentOfflineTask(taskId: Int): List<OfflineUpdateTaskBean?>?

    @Query("select * from offline_update_task_bean where taskId =:taskId and offlineType=3")
    fun getRecentOfflineEle(taskId: Int): List<OfflineUpdateTaskBean?>?

    @Query("delete from offline_update_task_bean where primaryId =:primaryId")
    fun deleteOfflineTaskFromId(primaryId: Int)

    @Query("delete from offline_update_task_bean where taskId =:taskId")
    fun deleteOfflineTaskFromTaskId(taskId: Int)

    @Query("delete from offline_update_task_bean")
    fun deleteAllOfflineTask()

    @Update(onConflict = OnConflictStrategy.REPLACE)
    fun update(offlineUpdateTaskBean: OfflineUpdateTaskBean)

}