package com.persagy.labsl.controller.planar

import com.persagy.labsl.models.entities.pbs.PlanarGraph
import com.persagy.labsl.models.entities.pbs.PlanarGraphPub
import com.persagy.labsl.models.entities.pbs.Building
import com.persagy.labsl.models.response.SCommonResponse
import com.persagy.labsl.services.planar.PlanarGraphService
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.SCreateResponse
import com.persagy.service.models.responses.SQueryResponse
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
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 wx  <zhangweixin@sagacloud.com>
 */
@Tag(name = "002、平面图")
@RestController
@RequestMapping("/planar/graph")
class PlanarGraphController {

    /**
     * 创建平面图
     *
     * @param planarGraph     待创建对象列表
     * @return 创建完成图对象列表
     */
    @Operation(summary ="-未发布-单个图形创建", description = "id和graphId为必填，图中会包含多个节点，详细节点结构见示例")
    @PostMapping("/drafts/create")
    fun create(@RequestBody planarGraph: PlanarGraph): SCreateResponse<PlanarGraph> {
        return PlanarGraphService.create(planarGraph)
    }

    /**
     * 提交图形
     *
     * @param  graph   待图对象
     * @return  图对象列表
     */
   @Operation(summary = "未发布-保存图形", description = "")
    @PostMapping("/drafts/save")
    fun save(@RequestBody graph: PlanarGraph): SCreateResponse<PlanarGraph> {
        return PlanarGraphService.save(graph)
    } // Function save()

    /**
     * 发布图形
     *
     * @param graph     待发布的图对象
     * @return 发布结果
     */
    @Operation(summary="未发布-发布图形", description =" Id 和 GraphId 必须填写")
    @PostMapping("/drafts/publish")
    fun pubDrawings(@RequestBody graph: PlanarGraphPub): SCreateResponse<PlanarGraphPub>{
        return PlanarGraphService.pubDrawings(graph)
    }


    /**
     * 图、移至或移出回收站
     *
     * @param idList    图例列表
     * @return 移出结果
     */
    @Operation(summary = "未发布-移至回收站", description = " Id 和 GraphId 必填")
    @PostMapping(value = ["/drafts/recycle"])
    fun recycle(@RequestBody idList: ArrayList<PlanarGraph>): SBaseResponse {
        return PlanarGraphService.recycle(idList)
    }

    /**
     * 已发布图形移至回收站
     *
     * @param idList    图列表
     * @return 移出结果
     */
    @Operation(summary = "已发布-图形移至回收站", description = "Id 和 GraphId 必填")
    @PostMapping(value = ["/pub/recycle"])
    fun recyclePub(@RequestBody idList: ArrayList<PlanarGraph>): SBaseResponse{
        return PlanarGraphService.recyclePub(idList)
    }

    /**
     * 更新图形信息
     *
     * @param request   更新的内容对象
     * @return 更新的结果
     */
    @Operation(summary = "未发布-更新图形信息", description = "Id 和 GraphId 必填")
    @PostMapping(value = ["/drafts/update"])
    fun updates(@RequestBody request: SUpdateRequest<PlanarGraph>): SBaseResponse {
        return PlanarGraphService.draftsUpdate(request)
    }

    /**
     * 查询图形信息    *********************************************************************************************************
     *
     * @param  request  查询条件
     * @return 查询结果
     */
    @Operation(summary = "未发布-查询图形信息", description = "state Draft(未发布)，state Recyle(回收站) ，Id 和 GraphId 必填")
    @PostMapping(value = ["/drafts/query"])
    fun query(@RequestBody request: SQueryRequest): SQueryResponse<Building> {
        return PlanarGraphService.pageQuerysDrafts(request)
    }

    /**
     * 未发布 - 读取图形所有节点
     *
     * @param graph  图例对象
     * @return 查询结果
     */
   @Operation(summary = "未发布-查询图形以及所有节点信息", description = "Id 和 GraphId 必填")
    @PostMapping(value = ["/drafts/read"])
    fun readDrafts(@RequestBody graph: PlanarGraph): SCommonResponse<PlanarGraph> {
        return PlanarGraphService.readDrafts(graph)
    } // Fun readDrafts()

    /**
     * 已发布 - 读取图形所有节点
     *
     * @param graph  图例对象
     * @return 查询结果
     */
   @Operation(summary = "已发布-查询图形以及所有节点信息", description = "Id 和 GraphId 必填")
    @PostMapping(value = ["/pub/read"])
    fun readPub(@RequestBody graph: PlanarGraphPub): SCommonResponse<PlanarGraphPub> {
        return PlanarGraphService.readPub(graph)
    } // Fun readPub()

    /**
     * 已发布图形查询   *****************************************************
     *
     * @param request  查询条件
     * @return 查询结果
     */
    @Operation(summary = "已发布-查询图形信息", description = "Id 和 GraphId 必填")
    @PostMapping(value = ["/pub/query"])
    fun querPub(@RequestBody request: SQueryRequest): SQueryResponse<Building> {
        return PlanarGraphService.pageQuerysPub(request)
    }

    /**
     * 更新图形信息
     *
     * @param request  更新的内容对象
     * @return 更新的结果
     */
    @Operation(summary = "已发布-更新图形信息", description = "")
    @PostMapping(value = ["/pub/update"])
    fun updatePub(@RequestBody request: SUpdateRequest<PlanarGraphPub>): SBaseResponse {
        return PlanarGraphService.pubUpdate(request)
    }

    /**
     * 已发布图形查询
     *
     * @param request  更新的内容对象
     * @return 更新的结果
     */
    @Operation(summary = "已发布-更新图形信息-根据文件夹或建筑楼层查询图形数据", description = "根据文件夹或建筑楼层查询图形数据")
    @PostMapping(value = ["/pub/flbd/query"])
    fun querPubs(@RequestBody request: SQueryRequest): SQueryResponse<PlanarGraphPub> {
        return PlanarGraphService.planarGraphPubService.pageQuery(request)
    }



    /**
     * 回收站- 恢复图形
     *
     * @param graph  图对象
     * @return 恢复结果
     */
   @Operation(summary = "回收站- 恢复图形", description = "Id 和 GraphId 必填 ")
    @PostMapping(value = ["recycle/recovery"])
    fun recovery(@RequestBody graph: PlanarGraph): SBaseResponse{
    return PlanarGraphService.recovery(graph)
    }

    /**
     * 根据id删除图形
     *
     * @param idList      图对象数组
     * @return 删除的结果信息
     */
    @Operation(summary = "回收站-根据id删除图形信息，删除图形", description = "Id 和 GraphId 必填 ")
    @PostMapping(value = ["recycle/delete"])
    fun delete(@RequestBody idList: ArrayList<PlanarGraph>): SBaseResponse {
        return PlanarGraphService.deleteByKeysList(idList)
    }

}