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

import androidx.room.*
import com.ys.bdtp.adm.mvvm.model.db.entity.task.FileEntity

/**
 * 表 file Dao
 */
@Dao
interface FileDao {
    @Query("select * from file")
    suspend fun getFiles(): List<FileEntity>

    @Query("select * from file where id = :id")
    suspend fun getFileById(id: String): FileEntity

    @Query("select * from file where ref_obj_id = :id")
    suspend fun getFileByRefId(id: String): List<FileEntity>

    @Query("select * from file where building_id = :id")
    suspend fun getFileByBuildingId(id: String): List<FileEntity>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insFile(vararg file: FileEntity)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insFiles(files: List<FileEntity>)

    @Update
    suspend fun updateFiles(files: List<FileEntity>)

    @Delete
    suspend fun delFile(file: FileEntity)

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