package com.yuchen.saas.park.service.controller.fire.inspect;

import com.yuchen.saas.park.api.dto.fire.inspect.plan.FireInspectPlanReqDTO;
import com.yuchen.saas.park.api.dto.fire.inspect.plan.FireInspectPlanSubmitReqDTO;
import com.yuchen.saas.park.api.vo.fire.inspect.plan.FireInspectPlanDetailVO;
import com.yuchen.saas.park.api.vo.fire.inspect.plan.FireInspectPlanTaskTableVO;
import com.yuchen.saas.park.api.vo.fire.inspect.plan.FireInspectPlanVO;
import com.yuchen.saas.park.service.service.fire.inspect.ISaasParkFireInspectPlanService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 巡检计划接口
 *
 * @author zhouhanwei
 * @since 2024-04-03
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/inspectPlan")
public class SaasParkFireInspectPlanController {

    private final ISaasParkFireInspectPlanService baseService;


    /**
     * 巡检计划分页列表
     */
    @PostMapping("/findFireInspectPlanPage")
    @ApiOperation(value = "巡检计划分页列表", notes = "巡检计划分页列表")
    public R<NestPage<FireInspectPlanVO>> findFireInspectPlanPage(@RequestBody FireInspectPlanReqDTO reqDTO) {
        return R.data(baseService.findFireInspectPlanPage(reqDTO));
    }

    /**
     * 查询巡检计划详情
     */
    @GetMapping("/getFireInspectPlan/{planId}")
    @ApiOperation(value = "查询巡检计划详情", notes = "查询巡检计划详情")
    public R<FireInspectPlanDetailVO> getFireInspectPlan(@PathVariable Long planId) {
        return R.data(baseService.getFireInspectPlan(planId));
    }

    /**
     * 查询巡检计划任务表
     */
    @GetMapping("/getPlanTaskTable/{planId}")
    @ApiOperation(value = "查询巡检计划任务表", notes = "查询巡检计划任务表")
    public R<FireInspectPlanTaskTableVO> getPlanTaskTable(@PathVariable Long planId) {
        return R.data(baseService.getPlanTaskTable(planId));
    }

    /**
     * 关闭计划
     */
    @PostMapping("/closePlan/{planId}")
    @ApiOperation(value = "关闭计划", notes = "关闭计划")
    public R closePlan(@PathVariable Long planId) {
        return R.status(baseService.closePlan(planId));
    }

    /**
     * 制定计划
     */
    @PostMapping("/addInspectPlan")
    @ApiOperation(value = "制定计划", notes = "制定计划")
    public R addInspectPlan(@Validated @RequestBody FireInspectPlanSubmitReqDTO reqDTO) {
        return R.status(baseService.addInspectPlan(reqDTO));
    }

    /**
     * 生成计划任务表
     */
    @PostMapping("/createPlanTaskInfo")
    @ApiOperation(value = "生成计划任务表", notes = "生成计划任务表")
    public R<FireInspectPlanTaskTableVO> createPlanTaskInfo(@Validated @RequestBody FireInspectPlanSubmitReqDTO reqDTO) {
        return R.data(baseService.createPlanTaskInfo(reqDTO));
    }

    /**
     * 下载计划任务
     */
    @PostMapping("/exportPlanTaskInfo")
    @ApiOperation(value = "下载计划任务", notes = "下载计划任务")
    public void exportPlanTaskInfo(@RequestParam("planId") Long planId, HttpServletResponse response) {
        baseService.exportPlanTaskInfo(planId, response);
    }
}
