package com.persagy.server.controllers.rel

import com.persagy.server.datacenter.models.entities.rel.RFlThroughFl
import com.persagy.server.datacenter.models.entities.rel.RFloorOtherThroughFloorList
import com.persagy.server.datacenter.models.entities.rel.RFloorThroughFloorOtherList
import com.persagy.server.services.rel.RFlThroughFlService
import com.persagy.base.extensions.toJson
import com.persagy.service.models.responses.SBaseResponse
import com.persagy.service.models.responses.SCreateResponse
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.slf4j.LoggerFactory
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 = ["021、关系-楼层的贯通"])
@RestController
@RequestMapping("/rel/fl-through-fl")
class RFlThroughFlController {
    companion object {
        /** 日志 */
        private val logger = LoggerFactory.getLogger(RFlThroughFlController::class.java)
    } // Companion object

    /**
     * 创建楼层的贯通关系
     *
     * @param   RFlThroughFl    楼层和楼层的关系对象
     * @return                  创建的结果信息
     */
    @ApiOperation(value = "创建楼层的贯通关系", notes = "必填项：FloorId（楼层id）、FloorOtherId（其他楼层id）")
    @PostMapping(value = ["/link"])
    fun create(@RequestBody rFlThroughFl: RFlThroughFl): SCreateResponse<RFlThroughFl>{
        logger.debug("build = ${rFlThroughFl.toJson()}")
        return RFlThroughFlService.create(rFlThroughFl)
    } // Function create()

    /**
     * 根据对象删除关系
     *
     * @param   rFlThroughFl    对象
     * @return                  删除的结果信息
     */
    @ApiOperation(value = "根据对象删除楼层的贯通关系，只针对一个对象", notes = "必填项：FloorId（楼层id）、FloorOtherId(其他楼层id)")
    @PostMapping(value = ["/unlink"])
    fun delete(@RequestBody rFlThroughFl: RFlThroughFl): SBaseResponse {
        return RFlThroughFlService.deletes(rFlThroughFl)
    } // Function delete()

    /**
     * 创建楼层的贯通关系
     *
     * @param   rFlThroughFl    楼层和其他楼层列表关系对象r
     * @return                  创建的结果信息
     */
    @ApiOperation(value = "楼层的贯通，楼层一对多", notes = "必填项：FloorId（楼层id）、FloorOtherIdList（其他楼层id列表）,测方法会覆盖以前的记录")
    @PostMapping(value = ["link-or"])
    fun createOr(@RequestBody rFlThroughFl: RFloorThroughFloorOtherList): SCreateResponse<RFlThroughFl>{
        logger.debug("floor =${rFlThroughFl.toJson()}")
        return RFlThroughFlService.createFl(rFlThroughFl)
    } // Function createOr()

    /**
     * 创建楼层的贯通关系
     *
     * @param   rFlThroughFl    其他楼层和楼层列表关系对象
     * @return                  创建的结果信息
     */
    @ApiOperation(value = "楼层的贯通，其他楼层一对多",notes = "必填项：FloorIdList（楼层id列表）、FloorOtherId（其他楼层id），测方法会覆盖以前的记录")
    @PostMapping(value = ["link-fl"])
    fun createFl(@RequestBody rFlThroughFl: RFloorOtherThroughFloorList): SCreateResponse<RFlThroughFl>{
        logger.debug("floor =${rFlThroughFl.toJson()}")
        return RFlThroughFlService.createsFl(rFlThroughFl)
    } // Function createFl()

} // Class RFlThroughFlController