package com.persagy.server.controllers

import com.persagy.server.datacenter.models.entities.objects.Equipment
import com.persagy.server.datacenter.models.entities.objects.GeneralSystem
import com.persagy.server.datacenter.models.entities.objects.ZoneIspace
import com.persagy.server.datacenter.models.entities.objects.ZoneSpace
import com.persagy.server.datacenter.models.requests.UpZoneSpaceBaseRequest
import com.persagy.server.models.requests.ZoneISpaceQueryRequest
import com.persagy.server.service.objects.*
import com.persagy.service.models.requests.SQueryRequest
import com.persagy.service.models.requests.SUpdateRequest
import com.persagy.service.models.responses.SBaseResponse
import com.persagy.service.models.responses.SQueryResponse
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
 * 空间接口
 *
 * @author 张维新
 */
@Api(tags = ["空间相关接口"])
@RestController
@RequestMapping("/space")
class SpaceController {

    @Autowired
    lateinit var service: ZoneSpaceService

    /**
     * 查询没有和当前空间绑定的系统
     *
     * @param   type        空间类型
     * @param   spaceId     空间id
     */
    @ApiOperation(value="查询没有和当前空间绑定的系统", notes="例如：prijectId=Pj4201050001,type=AirConditioningZone spaceId=Sp4201050001df2091cdf719443b80bb737aeabf0525 " +
            "spaceId 为当前空间id type为当前空间类型 ")
    @PostMapping(value = ["/unspace-in-sys"])
    fun unSpaceSys( type: String, spaceId: String,@RequestBody request: SQueryRequest): SQueryResponse<GeneralSystem> {
        return GeneralSystemService.unSpaceSys(type,spaceId, request)
    } // Function unSpaceSys()

    @ApiOperation(value="查询没有和当前空间绑定的设备", notes="例如：prijectId=Pj4201050001,type=AirConditioningZone spaceId=Sp4201050001df2091cdf719443b80bb737aeabf0525 " +
            "spaceId 为当前空间id type为当前空间类型 ")
    @PostMapping(value = ["/unspace-in-eq"])
    fun  unSpaceEq(type: String, spaceId: String,@RequestBody request: SQueryRequest): SQueryResponse<Equipment> {
        return EquipmentService.pageQueryEquip(type,spaceId,request)
    } // Function unSpaceEq()

    @ApiOperation(value="查询没有服务于当前空间的设备", notes="例如：prijectId=Pj4201050001,type=AirConditioningZone spaceId=Sp4201050001df2091cdf719443b80bb737aeabf0525 " +
            "spaceId 为当前空间id type为当前空间类型 ")
    @PostMapping(value = ["/unspace-for-eq"])
    fun  unSpaceForEq(type: String, spaceId: String,@RequestBody request: SQueryRequest): SQueryResponse<Equipment> {
        return EquipmentService.pageQueryForEquip(type,spaceId,request)
    } // Function unSpaceEq()

    /**
     * 空间内没有服务于当前空间的设备 根据坐标计算
     */
    @ApiOperation(value=" 空间内没有服务于当前空间的设备 根据坐标计算", notes="")
    @PostMapping(value = ["/unspace-for-eq-point"])
    fun unSpaceForEqPoint(type: String, spaceId: String,@RequestBody request: SQueryRequest): SQueryResponse<Equipment> {
        return  EquipmentService.unSpaceForEqPoint(type,spaceId,request)
    } // Function unSpaceForEqPoint()

    /**
     * 空间内没有和空间关联的设备 根据坐标计算
     */
    @ApiOperation(value=" 空间内没有和空间关联的设备 根据坐标计算", notes="")
    @PostMapping(value = ["/unspace-fIn-eq-point"])
    fun unSpaceInEqPoint(type: String, spaceId: String,@RequestBody request: SQueryRequest): SQueryResponse<Equipment> {
        return  EquipmentService.unSpaceInEqPoint(type,spaceId,request)
    } // Function unSpaceForEqPoint()

    /**
     * 未关联业务空间的元空间
     */
    @ApiOperation(value=" 未关联业务空间的元空间", notes="")
    @PostMapping(value = ["/unspace-ispace"])
    fun unSpaceIspace(objectType: String, @RequestBody request: ZoneISpaceQueryRequest): SQueryResponse<ZoneIspace> {
        return ISpaceService.unSpaceIspace(objectType,request)
    } // Function unSpaceIspace()

    /**
    * 同一建筑楼层中，包含该位置标签坐标的所有类型的业务空间实例
     * projectId = Pj1101080029
     * x = 148409.372029545
     * y = -200252.644431612
     * {
        "Filters": " buildingId = 'Bd1101080029dddbfba4cdef11e9a316497519c1daff' and floorId = 'Fl110108002946c52d23cf9311e985165f9ca2299edb'",
        "PageNumber": 1,
        "PageSize": 50
       }
    */
    @ApiOperation(value="同一建筑楼层中，包含该位置标签坐标的所有类型的业务空间实例", notes="  projectId = Pj1101080029\n" +
            "      x = 148409.372029545\n" +
            "      y = -200252.644431612\n{\n" +
            "        \"Filters\": \" buildingId = 'Bd1101080029dddbfba4cdef11e9a316497519c1daff' and floorId = 'Fl110108002946c52d23cf9311e985165f9ca2299edb'\",\n" +
            "        \"PageNumber\": 1,\n" +
            "        \"PageSize\": 50\n" +
            "       }")
    @PostMapping(value = ["/in-bdfl-zonespacebase"])
    fun inBdflZoneSpace(X: String, Y: String, @RequestBody request: SQueryRequest): SQueryResponse<ZoneSpace> {
        return service.inBdflZoneSpace(X,Y,request)
    } // Function unSpaceIspace()

    /**
     * 修改空间图片信息
     * @param request 空间信息
     */
    @ApiOperation(value="修改空间图片信息", notes="（全部必传）ObjectType 空间类型 RoomID，Pic")
    @PostMapping(value = ["/update-space-picinfo"])
    fun updateSpacePicInfo(@RequestBody request: SUpdateRequest<UpZoneSpaceBaseRequest>): SBaseResponse {
        return service.updateSpacePicInfo(request)
    } // Function updateSpacePicInfo

//    /**
//     * 统计 属于多建筑楼层的空间
//     */
//    @ApiOperation(value="统计 属于多建筑楼层的空间", notes="")
//    @PostMapping(value = ["/space-bd-fl"])
//    fun spaceBdFl(): SCountResponse {
//        return ZoneAirConditioningService.spaceBdFls()
//    } // Function spaceBdFl()

    /**
     * 统计 属于多建筑楼层的空间数据
     */
    @ApiOperation(value="统计 属于多建筑楼层的空间数据", notes="")
    @PostMapping(value = ["/space-bd-fl-data"])
    fun spaceBdFlObj(@RequestBody request: SQueryRequest): SQueryResponse<ZoneSpace> {
        return ZoneSpaceBaseService.pageQuery(request)
    } // Function spaceBdFl()

    /**
     * 查询元空间关系 邻接关系、建筑交通网络 、 空气流通网络、 光照辐射网络
     */
//    @ApiOperation(value="查询元空间关系 邻接关系SpaceNeighborhood、建筑交通网络TrafficNetwork 、 空气流通网络ConvectionNetwork、 光照辐射网络RadiationNetwork", notes="")
//    @PostMapping(value = ["/space-rel"])
//    fun spatialRelationship(@RequestBody spatialRelationship: SpatialRelationship): SQueryResponse<RSpatialConnection>{
//        return ZoneSpaceBaseService.spatialRelationship(spatialRelationship)
//    }

}  // Class SpaceController