package org.wcs.serve.controller.app;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.wcs.model.dto.serve.conveyTask.AddConveyTaskReq;
import org.wcs.model.dto.serve.conveyTask.QueryConveyTaskReq;
import org.wcs.model.dto.serve.conveyTask.ReporterConveyTaskStatusReq;
import org.wcs.model.vo.serve.AppServeDataResponse;
import org.wcs.model.vo.serve.AppServeResponse;
import org.wcs.model.vo.serve.common.PageDataResponse;
import org.wcs.model.vo.serve.conveyTask.QueryConveyTaskVo;
import org.wcs.serve.service.intf.IConveyTaskService;

/**
 * 箱式线任务
 */
@RestController
@RequestMapping("/app/conveyTask")
@ResponseBody
@RequiredArgsConstructor
public class ConveyTaskController {

    private final IConveyTaskService conveyTaskService;

    /**
     * 查询箱式线任务
     * @param request 查询参数
     * @param pageSize 每页数量
     * @param pageIndex 页码
     * @return 结果
     */
    @PostMapping("queryConveyTask")
    public AppServeDataResponse<PageDataResponse<QueryConveyTaskVo>> queryConveyTask(@RequestBody QueryConveyTaskReq request, @RequestParam("pageSize") Integer pageSize, @RequestParam("pageIndex") Integer pageIndex) {
        return conveyTaskService.queryConveyTask(request, pageSize, pageIndex);
    }

    /**
     * 箱式线任务查询（备份）
     * @param request 查询参数
     * @param pageSize 每页数量
     * @param pageIndex 页码
     * @return 箱式线任务列表
     */
    @PostMapping("queryConveyTaskBak")
    public AppServeDataResponse<PageDataResponse<QueryConveyTaskVo>> queryConveyTaskBak(@RequestBody QueryConveyTaskReq request, @RequestParam("pageSize") Integer pageSize, @RequestParam("pageIndex") Integer pageIndex) {
        return conveyTaskService.queryConveyTaskBak(request, pageSize, pageIndex);
    }

    /**
     * 新增箱式线任务
     * @param request 新增参数
     * @return 结果
     */
    @PostMapping("addConveyTask")
    public AppServeResponse addConveyTask(@RequestBody @Validated AddConveyTaskReq request) {
        return conveyTaskService.addConveyTask(request);
    }

    /**
     * 修改箱式线任务状态
     * @param taskId 任务ID
     * @param status 状态
     * @return 结果
     */
    @PutMapping("updateConveyTaskStatus")
    public AppServeResponse updateConveyTaskStatus(@RequestParam("taskId") @NotBlank(message = "任务ID不能为空") String taskId, @RequestParam("taskStatus") @NotNull(message = "状态不能为空") Integer status) {
        return conveyTaskService.updateConveyTaskStatus(taskId, status);
    }

    /**
     * 完成箱式线任务
     * @param taskId 任务ID
     * @param arriveLocation 到达位置
     * @return 结果
     */
    @PutMapping("completeConveyTask")
    public AppServeResponse completeConveyTask(@RequestParam("taskId") @NotBlank(message = "任务ID不能为空") String taskId, @RequestParam("arriveLocation") @NotNull(message = "到达位置不能为空") String arriveLocation) {
        return conveyTaskService.completeConveyTask(taskId, arriveLocation);
    }

    /**
     * 取消箱式线任务
     * @param taskId 箱式线任务ID
     * @return 取消结果
     */
    @DeleteMapping("cancelConveyTask")
    public AppServeResponse cancelConveyTask(@RequestParam("taskId") @NotBlank(message = "箱式线任务ID不能为空") String taskId) {
        return conveyTaskService.cancelConveyTask(taskId);
    }

    /**
     * 汇报箱式线任务完成
     * @param request 汇报参数
     * @return 汇报结果
     */
    @PostMapping("reporterConveyTaskComplete")
    public AppServeResponse reporterConveyTaskComplete(@RequestBody @Validated ReporterConveyTaskStatusReq request) {
        return conveyTaskService.reporterConveyTaskComplete(request);
    }

    /**
     * 汇报箱式线任务取消
     * @param request 汇报参数
     * @return 汇报结果
     */
    @PostMapping("reporterConveyTaskCancel")
    public AppServeResponse reporterConveyTaskCancel(@RequestBody @Validated ReporterConveyTaskStatusReq request) {
        return conveyTaskService.reporterConveyTaskCancel(request);
    }

    /**
     * 汇报箱式线任务完成 ---- 已经备份的任务
     * @param request 汇报参数
     * @return 汇报结果
     */
    @PostMapping("reporterConveyTaskBakComplete")
    public AppServeResponse reporterConveyTaskBakComplete(@RequestBody @Validated ReporterConveyTaskStatusReq request) {
        return conveyTaskService.reporterConveyTaskBakComplete(request);
    }

    /**
     * 汇报箱式线任务取消 ---- 已经备份的任务
     * @param request 汇报参数
     * @return 汇报结果
     */
    @PostMapping("reporterConveyTaskBakCancel")
    public AppServeResponse reporterConveyTaskBakCancel(@RequestBody @Validated ReporterConveyTaskStatusReq request) {
        return conveyTaskService.reporterConveyTaskBakCancel(request);
    }

    /**
     * 导出箱式线任务列表
     * @param response 响应
     * @param request 查询参数
     */
    @PostMapping("exportConveyTaskBak")
    public void exportConveyTaskBak(HttpServletResponse response, @RequestBody @Validated QueryConveyTaskReq request) {
        conveyTaskService.exportConveyTaskBak(response, request);
    }


}
