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

import com.yuchen.saas.park.api.dto.fire.inspect.plan.AddTemporaryTaskReqDTO;
import com.yuchen.saas.park.api.dto.fire.inspect.plan.AdjustPlanTaskReqDTO;
import com.yuchen.saas.park.api.dto.fire.inspect.plan.ClosePlanTaskReqDTO;
import com.yuchen.saas.park.api.dto.fire.inspect.plan.FireInspectPlanTaskReqDTO;
import com.yuchen.saas.park.api.vo.fire.inspect.plan.FireInspectPlanTaskCountVO;
import com.yuchen.saas.park.api.vo.fire.inspect.plan.FireInspectPlanTaskDetailVO;
import com.yuchen.saas.park.api.vo.fire.inspect.plan.FireInspectPlanTaskVO;
import com.yuchen.saas.park.service.service.fire.inspect.ISaasParkFireInspectPlanTaskService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.log.exception.ServiceException;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.secure.ContextUser;
import org.nest.springwrap.core.secure.utils.AuthUtil;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * 巡检任务接口
 *
 * @author zhouhanwei
 * @since 2024-04-03
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/inspectPlanTask")
public class SaasParkFireInspectPlanTaskController {

    private final ISaasParkFireInspectPlanTaskService baseService;

    /**
     * 巡检任务分页列表
     */
    @PostMapping("/findFireInspectPlanTaskPage")
    @ApiOperation(value = "巡检计划分页列表", notes = "巡检计划分页列表")
    public R<NestPage<FireInspectPlanTaskVO>> findFireInspectPlanTaskPage(@RequestBody FireInspectPlanTaskReqDTO reqDTO) {
        ContextUser contextUser = AuthUtil.getUser();
        if (Objects.isNull(contextUser)) {
            throw new ServiceException("用户不存在");
        }
        reqDTO.setCustomerId(contextUser.getCustomerManageId());
        return R.data(baseService.findFireInspectPlanTaskPage(reqDTO));
    }

    /**
     * 巡检任务列表统计
     */
    @PostMapping("/getPlanTaskCount")
    @ApiOperation(value = "巡检任务列表统计", notes = "巡检任务列表统计")
    public R<FireInspectPlanTaskCountVO> getPlanTaskCount(@RequestBody FireInspectPlanTaskReqDTO reqDTO) {
        return R.data(baseService.getPlanTaskCount(reqDTO));
    }

    /**
     * 巡检任务详情
     */
    @GetMapping("/getFireInspectPlanTaskById/{planTaskId}")
    @ApiOperation(value = "巡检任务详情", notes = "巡检任务详情")
    public R<FireInspectPlanTaskDetailVO> getFireInspectPlanTaskById(@PathVariable Long planTaskId) {
        return R.data(baseService.getFireInspectPlanTaskById(planTaskId));
    }

    /**
     * 关闭任务
     */
    @PostMapping("/closePlanTask")
    @ApiOperation(value = "关闭任务", notes = "关闭任务")
    public R closePlanTask(@Validated @RequestBody ClosePlanTaskReqDTO reqDTO) {
        return R.status(baseService.closePlanTask(reqDTO));
    }

    /**
     * 新增临时任务
     */
    @PostMapping("/addTemporaryTask")
    @ApiOperation(value = "新增临时任务", notes = "新增临时任务")
    public R addTemporaryTask(@Validated @RequestBody AddTemporaryTaskReqDTO reqDTO) {
        return R.status(baseService.addTemporaryTask(reqDTO));
    }

    /**
     * 调整任务
     */
    @PostMapping("/adjustPlanTask")
    @ApiOperation(value = "调整任务", notes = "调整任务")
    public R adjustPlanTask(@Validated @RequestBody AdjustPlanTaskReqDTO reqDTO) {
        return R.status(baseService.adjustPlanTask(reqDTO));
    }
}
