package org.wcs.serve.controller.app;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.wcs.model.dto.serve.etagTask.AddEtagTaskReq;
import org.wcs.model.dto.serve.etagTask.EtagTaskQueryReq;
import org.wcs.model.dto.serve.etagTask.UpdateEtagTaskReq;
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.etagTask.EtagTaskBakVo;
import org.wcs.model.vo.serve.etagTask.EtagTaskVo;
import org.wcs.serve.service.intf.IEtagTaskService;

import javax.validation.constraints.NotNull;

/**
 * 电子标签任务控制器
 */
@RestController
@RequestMapping("/app/etagTask")
@ResponseBody
@RequiredArgsConstructor
public class EtagTaskController {

    private final IEtagTaskService etagTaskService;

    /**
     * 查询电子标签任务
     * @param request 查询参数
     * @param pageIndex 页码
     * @param pageSize 页大小
     * @return 响应
     */
    @SaCheckPermission("etagTask:query")
    @PostMapping("/queryEtagTask")
    public AppServeDataResponse<PageDataResponse<EtagTaskVo>> queryEtagTask(@RequestBody EtagTaskQueryReq request, @RequestParam("pageIndex") @NotNull(message = "页码不能为空") Integer pageIndex, @RequestParam("pageSize") @NotNull(message = "页大小不能为空") Integer pageSize) {
        return etagTaskService.queryEtagTask(request, pageIndex, pageSize);

    }

    /**
     * 新增电子标签任务
     * @param request 新增参数
     * @return 响应
     */
    @SaCheckPermission("etagTask:add")
    @PostMapping("/addEtagTask")
    public AppServeResponse addEtagTask(@RequestBody @Validated AddEtagTaskReq request) {
        return etagTaskService.addEtagTask(request);
    }

    /**
     * 修改电子标签任务
     * @param request 修改参数
     * @return 响应
     */
    @SaCheckPermission("etagTask:edit")
    @PostMapping("/updateEtagTask")
    public AppServeResponse updateEtagTask(@RequestBody @Validated UpdateEtagTaskReq request) {
        return etagTaskService.updateEtagTask(request);
    }

    /**
     * 查询电子标签任务 ---- 备份表
     * @param request 查询参数
     * @param pageIndex 页码
     * @param pageSize 页大小
     * @return 响应
     */
    @SaCheckPermission("etagTaskBak:query")
    @PostMapping("/queryEtagTaskBak")
    public AppServeDataResponse<PageDataResponse<EtagTaskBakVo>> queryEtagTaskBak(@RequestBody EtagTaskQueryReq request, @RequestParam("pageIndex") @NotNull(message = "页码不能为空") Integer pageIndex, @RequestParam("pageSize") @NotNull(message = "页大小不能为空") Integer pageSize) {
        return etagTaskService.queryEtagTaskBak(request, pageIndex, pageSize);

    }

    /**
     * 确认标签任务
     * @param taskId 任务ID
     * @param confirmNum 确认数量
     * @return 响应
     */
    @SaCheckPermission(value = {"etagTask:upload", "etagTaskBak:upload"}, mode = SaMode.OR)
    @PutMapping("/uploadTaskConfirmNum")
    public AppServeResponse uploadTaskConfirmNum(@RequestParam("taskId") @NotBlank(message = "任务ID不允许未为空") String taskId, @RequestParam("confirmNum") @NotNull(message = "确认数不能为空") @Min(value = 0, message = "确认数不能小于0") Integer confirmNum) {
        return etagTaskService.uploadTaskConfirmNum(taskId, confirmNum);
    }



}
