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

import androidx.room.*
import com.framework.mvvm.model.db.entity.PipeConfigEntity
import com.framework.mvvm.model.db.entity.PipeEntity

/**
 * 管道表 Dao
 */
@Dao
interface PipeDao {
    @Query("select * from pipe")
    suspend fun getPipes(): List<PipeEntity>

    @Query("select * from pipe where id = :id")
    suspend fun getPipeById(id: String): PipeEntity

    @Query("select * from pipe where building_id = :id")
    suspend fun getPipeByBuildingId(id: String): List<PipeEntity>

    @Query("select * from pipe where obj_from = :id and pipe_type = :pipeType and pipe_sub_type=:pipeSubType and valid = 1")
    suspend fun getPipeByIdFrom(id: String, pipeType: String, pipeSubType: String): List<PipeEntity>

    @Query("select * from pipe where obj_to = :id and pipe_type = :pipeType and pipe_sub_type=:pipeSubType and valid = 1")
    suspend fun getPipeByIdTo(id: String, pipeType: String, pipeSubType: String): List<PipeEntity>

    @Query("select * from pipe where floor_id = :floorId and valid = 1")
    suspend fun getPipeByFloorId(floorId: String): List<PipeEntity>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insPipe(vararg pipe: PipeEntity)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insPipes(pipes: List<PipeEntity>)

    @Update
    suspend fun updatePipe(pipe: PipeEntity)

    @Update
    suspend fun updatePipes(pipes: List<PipeEntity>)

    @Delete
    suspend fun delConfig(config: PipeConfigEntity)
}