package com.ys.bdtp.adm.mvvm.model.db.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.ys.bdtp.adm.mvvm.model.db.entity.task.QrCodeEntity

/**
 * 表 qr_code Dao
 */
@Dao
interface QrCodeDao {
    @Query("select * from qr_code")
    suspend fun getQrCodes(): List<QrCodeEntity>

    @Query("select * from qr_code where id = :id")
    suspend fun getQrCodeById(id: String): QrCodeEntity

    @Query("select * from qr_code where obj_id = :id")
    suspend fun getQrCodeByObjId(id: String): List<QrCodeEntity>?

    @Query("select * from qr_code where building_id = :id")
    suspend fun getQrCodeByBuildingId(id: String): List<QrCodeEntity>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insQrCode(vararg qrCode: QrCodeEntity)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insQrCodes(qrCodes: List<QrCodeEntity>)

    @Update
    suspend fun updateQrCodes(qrCodes: List<QrCodeEntity>)

    @Delete
    suspend fun delQrCode(qrCode: QrCodeEntity)

    @Query("select count(*) from qr_code where project_id = :projectId and (state = 0 or state = 1)")
    suspend fun countUnDone(projectId: String): Int

}