package com.persagy.labsl.controller.planar

import com.persagy.database.SFilter
import com.persagy.labsl.Opts
import com.persagy.labsl.models.entities.pbs.QbsFolder
import com.persagy.labsl.services.planar.QbsFolderService
import com.persagy.service.models.requests.SCountRequest
import com.persagy.service.models.requests.SCreateRequest
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.SCountResponse
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>
 * @date  2020/12/1 15:32
 */
@Tag(name = "001、文件夹")
@RestController
@RequestMapping("/planar/folder")
class QbsFolderController {

    /**
     * 创建文件夹
     *
     * @param request    对象列表
     * @return 创建完成对象列表
     */
    @Operation(summary ="创建文件夹", description = "name 不可以为空，不可以与已存在文件夹名称重复")
    @PostMapping("/create")
    fun create(@RequestBody request: SCreateRequest<QbsFolder>): SCreateResponse<QbsFolder> {
        return QbsFolderService.creates(request)
    }

    /**
     * 根据id删除文件夹
     *
     * @param idList   文件夹对象数组
     * @return 删除的结果信息
     */
    @Operation(summary = "根据id删除文件夹", description = "id  必填 ")
    @PostMapping(value = ["/delete"])
    fun delete(@RequestBody idList: ArrayList<QbsFolder>): SBaseResponse {
        return QbsFolderService.deletes(idList)
    }

    /**
     * 更新信息
     *
     * @param request   更新的内容对象
     * @return 更新的结果
     */
    @Operation(summary = "更新文件夹信息", description = "id 必填")
    @PostMapping(value = ["/update"])
    fun update(@RequestBody request: SUpdateRequest<QbsFolder>): SBaseResponse {
        return QbsFolderService.updates(request)
    }

    /**
     * 文件夹查询
     *
     * @param request  查询条件
     * @return 查询结果
     */
    @Operation(summary = "文件夹查询", description = "")
    @PostMapping(value = ["/query"])
    fun query(@RequestBody request: SQueryRequest): SQueryResponse<QbsFolder> {
        return QbsFolderService.pageQuery(request, arrayListOf(SFilter.eq("projectId", Opts.projectId!!)))
    }

    /**
     * 根据条件查询统计数量
     */
    @Operation(summary = "根据条件查询统计数量", description = "")
    @PostMapping(value = ["/count"])
    fun count(@RequestBody request: SCountRequest): SCountResponse {
        return QbsFolderService.count(request,arrayListOf(SFilter.eq("projectId", Opts.projectId!!)))
    }

}