package com.persagy.revit.dao.mapper

import com.persagy.revit.dao.FloorDAO
import com.persagy.revit.models.modelFile.FloorFolderName
import com.persagy.revit.models.modelFile.FloorModel
import org.apache.ibatis.annotations.Mapper
import org.apache.ibatis.annotations.Param
import org.apache.ibatis.annotations.Select
import org.apache.ibatis.annotations.UpdateProvider
import org.springframework.stereotype.Repository

/**
 *
 * @author jxing
 */
@Repository
@Mapper
interface FloorMapper {

    @Select("select id, project_id as projectId, floor_name as floorName, current_model_id as currentModelId, folder_id as folderId" +
            ", bind_floor_ids from revit.model_floor where bind_floor_ids ??& array[#{dcFloorId}]")
    fun getFloorByDcFloorId(@Param("dcFloorId") dcFloorId: String) : ArrayList<FloorModel>?

    @UpdateProvider(type = FloorDAO::class, method = "dynamicUpdate")
    fun updateFloorCurrentModelId(@Param("floorId") floorId: String, @Param("oldModelId") oldModelId: String?, @Param("modelId") modelId: String?) : Int

    @Select("select fl.id floorId, fl.floor_name floorName, folder.id folderId, folder.name folderName " +
            "from revit.model_floor fl left join revit.model_folder folder " +
            "on fl.folder_id = folder.id where fl.id = #{floorId}")
    fun getFloorFolderName(@Param("floorId") floorId: String) : FloorFolderName?

    @Select("select public.rel_affected_space(#{floorId})")
    fun calcAffected(@Param("floorId") floorId: String) : Boolean?
}