package org.wcs.serve.controller.app;


import jakarta.servlet.http.HttpServletResponse;
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.stockSingleTask.AddSingleTaskReq;
import org.wcs.model.dto.serve.stockSingleTask.QueryStockSingleTaskReq;
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.stockSingleTask.AppStockSingleTaskVo;
import org.wcs.serve.service.intf.IStockSingleTaskService;

@RestController
@RequestMapping("/app/stockSingleTask")
@ResponseBody
@RequiredArgsConstructor
public class StockSingleTaskController {

    private final IStockSingleTaskService stockSingleTaskService;

    /**
     * 分页查询任务
     * @param request 查询参数
     * @param pageSize 每页数量
     * @param pageIndex 页码
     * @return 结果
     */
    @PostMapping("/query")
    public AppServeDataResponse<PageDataResponse<AppStockSingleTaskVo>> query(@RequestBody QueryStockSingleTaskReq request, @RequestParam("pageSize") @NotNull(message = "分页单页大小不能为空") Integer pageSize , @RequestParam("pageIndex") @NotNull(message = "分页页码不能为空") Integer pageIndex) {
        return stockSingleTaskService.query(request, pageSize, pageIndex);
    }

    /**
     * 分页查询任务
     * @param request 查询参数
     * @param pageSize 每页数量
     * @param pageIndex 页码
     * @return 结果
     */
    @PostMapping("/queryBak")
    public AppServeDataResponse<PageDataResponse<AppStockSingleTaskVo>> queryBak(@RequestBody QueryStockSingleTaskReq request, @RequestParam("pageSize") @NotNull(message = "分页单页大小不能为空") Integer pageSize , @RequestParam("pageIndex") @NotNull(message = "分页页码不能为空") Integer pageIndex) {
        return stockSingleTaskService.queryBak(request, pageSize, pageIndex);
    }

    /**
     * 下载任务
     * @param request 添加单任务数据
     */
    @PostMapping("/downLoadBak")
    public void downLoadBak(HttpServletResponse response, @RequestBody QueryStockSingleTaskReq request) {
        stockSingleTaskService.downLoadBak(response, request);
    }

    /**
     * 添加单任务
     * @param request 添加单任务数据
     * @return 结果
     */
    @PostMapping("/addSingleTask")
    public AppServeResponse addSingleTask(@RequestBody @Validated AddSingleTaskReq request) {
        return stockSingleTaskService.addSingleTask(request);
    }

    /**
     * 新增plc任务id
     * @param taskId 任务id
     * @return 结果
     */
    @PutMapping("/newPlcTaskId/{taskId}")
    public AppServeResponse newPlcTaskId(@PathVariable String taskId) {
        return stockSingleTaskService.newPlcTaskId(taskId);
    }

    /**
     * 更新任务状态
     * @param taskId 任务id
     * @param taskStatus 任务状态
     * @return 结果
     */
    @PutMapping("/updateTaskStatus")
    public AppServeResponse updateTaskStatus(@RequestParam("taskId") String taskId, @RequestParam("taskStatus") Integer taskStatus) {
        return stockSingleTaskService.updateTaskStatus(taskId, taskStatus);
    }

    /**
     * 完成任务
     * @param taskId 要完成的任务号
     * @return  结果
     */
    @PutMapping("/completeTask/{taskId}")
    public AppServeResponse completeTask(@PathVariable String taskId) {
        return stockSingleTaskService.completeTask(taskId);
    }

    /**
     * 取消任务
     * @param taskId 要取消的任务号
     * @return  结果
     */
    @PutMapping("/cancelTask/{taskId}")
    public AppServeResponse cancelTask(@PathVariable String taskId) {
        return stockSingleTaskService.cancelTask(taskId);
    }




}
