package com.framework.mvvm.model.db.dao

import androidx.room.*
import com.framework.mvvm.model.db.entity.ObjectEntity

/**
 * 表 object Dao
 */
@Dao
interface ObjectDao {
    @Query("select * from object")
    suspend fun getObjects(): List<ObjectEntity>

    @Query("select * from object where id = :id")
    suspend fun getObjectById(id: String): ObjectEntity

    @Query("select * from object where obj_type = :objType")
    suspend fun getObjectByObjType(objType: String): List<ObjectEntity>

    @Query("select * from object where building_id = :buildingId and obj_type=:type")
    suspend fun getObjectByBuildingId(buildingId: String, type: String): List<ObjectEntity>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insObject(vararg obj: ObjectEntity)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insObjects(objects: List<ObjectEntity>)

    @Delete
    suspend fun delObject(obj: ObjectEntity)

    /**
     * 返回楼层类型的 ObjectEntity
     */
    @Query("select * from object where obj_type = 'floor'")
    suspend fun getFloors(): List<ObjectEntity>

    /**
     * 更新 ObjectEntity
     */
    @Update
    suspend fun upObject(obj: ObjectEntity)

    // @Transaction
    // @Query("select * from object")
    // fun getObjectAndInfosWithOutlines() : List<ObjectAndInfosWithOutlines>
}