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

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

/**
 * 表 space Dao
 */
@Dao
interface JobSpaceDao {
    @Query("select * from job_space")
    suspend fun getSpaces(): List<JobSpaceEntity>

    @Query("select * from job_space where id = :id")
    suspend fun getSpaceById(id: String): JobSpaceEntity

    @Query("select * from job_space where space_id = :id and valid = 1")
    suspend fun getSpaceBySpaceId(id: String): JobSpaceEntity

    @Query("select * from job_space where floor_id = :id and arch_state =:archState and valid = 1")
    suspend fun getSpaceByArchStateFloorId(id: String, archState: String): List<JobSpaceEntity>

    @Query("select * from job_space where floor_id = :id and equip_state =:equipState and valid = 1")
    suspend fun getSpaceByEquipStateFloorId(id: String, equipState: String): List<JobSpaceEntity>

    @Query("select * from job_space where building_id = :id")
    suspend fun getSpaceByBuildingId(id: String): List<JobSpaceEntity>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insSpace(vararg space: JobSpaceEntity)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insSpaces(spaces: List<JobSpaceEntity>)

    @Update
    suspend fun updateSpaces(spaces: List<JobSpaceEntity>)

    @Delete
    suspend fun delSpace(space: JobSpaceEntity)

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