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

import androidx.room.*
import com.ys.bdtp.adm.mvvm.model.db.entity.task.ProjectEntity
import com.ys.bdtp.adm.mvvm.model.db.relation.ProjectWithBuildingAndFloors
import com.ys.bdtp.adm.mvvm.model.db.relation.ProjectWithBuildings
import kotlinx.coroutines.flow.Flow

/**
 * project 表访问接口
 * @author bai
 */
@Dao
interface ProjectDao {

    @Query("select * from project")
    fun getProjects(): Flow<List<ProjectEntity>>

    @Query("select * from project where id = :id")
    suspend fun getProjectById(id: String): ProjectEntity

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insProjects(projects: List<ProjectEntity>)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insProject(vararg project: ProjectEntity)

    @Delete
    suspend fun delProject(project: ProjectEntity)

    /**
     *
     */
    @Transaction
    @Query("select * from project")
    fun getProjectWithBuildings(): Flow<List<ProjectWithBuildings>>

    /**
     * 多表查询
     */
    @Transaction
    @Query("select * from project")
    fun getProjectWithBuildingAndFloors(): Flow<List<ProjectWithBuildingAndFloors>>

    /**
     * 多表查询
     */
    @Transaction
    @Query("select * from project where id = :id")
    fun getProjectWithBuildingAndFloorsById(id: String): Flow<ProjectWithBuildingAndFloors>


}