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

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

/**
 * 表 space Dao
 */
@Dao
interface WorkspaceDao {
    @Query("select * from workspace")
    suspend fun getSpaces(): List<WorkspaceEntity>

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

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

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

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

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

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

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

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

    @Delete
    suspend fun delSpace(space: WorkspaceEntity)

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