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

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

/**
 * 表 serve_area Dao
 */
@Dao
interface ServeAreaDao {

    @Query("select * from serve_area")
    suspend fun getAreas(): List<ServeAreaEntity>

    @Query("select * from serve_area where building_id = :id")
    suspend fun getAreasByBuildingId(id: String): List<ServeAreaEntity>

    @Query("select * from serve_area where obj_id = :id and valid = 1")
    suspend fun getAreasByObjId(id: String): ServeAreaEntity?

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertAreas(areas: List<ServeAreaEntity>)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertArea(areas: ServeAreaEntity)

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