package com.module.database.room.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.DeleteTable
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.module.database.room.entity.BillBean
import com.module.database.room.entity.LocalOrderBean
import com.module.database.room.entity.WarringBean

@Dao
interface LocalOrderDao {

    @Query("SELECT * FROM localorder")
    suspend fun getAll():List<LocalOrderBean>

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    suspend fun insert(localOrderBean: LocalOrderBean)

    @Update
    suspend fun update(localOrderBean: LocalOrderBean): Int

    @Delete
    suspend fun delete(localOrderBean: LocalOrderBean): Int

    @Query("DELETE FROM localorder")
    suspend fun deleteAll():Int

    @Query("SELECT * FROM localorder WHERE syncStatus = 0 ORDER BY time ASC")
    suspend fun getUnsyncedData(): List<LocalOrderBean>

    @Query("Select * from localorder where time between :startTime and :endTime order by time desc")
    suspend fun queryTime(startTime:String,endTime:String):List<LocalOrderBean>

    @Query("UPDATE localorder SET syncStatus = 1 WHERE id = :id")
    suspend fun markAsSyncing(id: Long)


    // 标记为已上传（状态2）
    @Query("UPDATE localorder SET syncStatus = 2 WHERE id = :id")
    suspend fun markAsSynced(id: Long)
}