package org.wcs.serve.controller.app;

import jakarta.servlet.http.HttpServletResponse;
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.trayConveyLocation.AddTrayConveyLocationReq;
import org.wcs.model.dto.serve.trayConveyLocation.QueryTrayConveyLocationReq;
import org.wcs.model.dto.serve.trayConveyLocation.UpdateTrayConveyLocationReq;
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.trayConveyLocation.QueryTrayConveyLocationVo;
import org.wcs.model.vo.serve.trayConveyLocation.TrayConveyStatusVo;
import org.wcs.serve.service.intf.ITrayConveyLocationService;

@RestController
@RequestMapping("/app/trayConveyLocation")
@ResponseBody
@RequiredArgsConstructor
public class TrayConveyLocationController {

    private final ITrayConveyLocationService trayConveyLocationService;

    /**
     * 分页查询托盘输送点位数据
     * @param request 查询参数
     * @param pageSize 分页单页大小
     * @param pageIndex 分页页码
     * @return 结果
     */
    @PostMapping("queryTrayConveyLocation")
    public AppServeDataResponse<PageDataResponse<QueryTrayConveyLocationVo>> queryTrayConveyLocation(@RequestBody QueryTrayConveyLocationReq request, @RequestParam("pageSize") Integer pageSize, @RequestParam("pageIndex") Integer pageIndex) {
        return trayConveyLocationService.queryTrayConveyLocation(request, pageSize, pageIndex);
    }

    /**
     * 新增托盘输送点位数据
     * @param request 新增参数
     * @return 结果
     */
    @PostMapping("addTrayConveyLocation")
    public AppServeResponse addTrayConveyLocation(@RequestBody @Validated AddTrayConveyLocationReq request) {
        return trayConveyLocationService.addTrayConveyLocation(request);
    }

    /**
     * 修改托盘输送点位数据
     * @param request 修改参数
     * @return 结果
     */
    @PostMapping("updateTrayConveyLocation")
    public AppServeResponse updateTrayConveyLocation(@RequestBody @Validated UpdateTrayConveyLocationReq request) {
        return trayConveyLocationService.updateTrayConveyLocation(request);
    }

    /**
     * 查询托盘输送点位状态数据
     * @param conveyId 输送点位ID
     * @return 状态数据
     */
    @GetMapping("queryTrayConveyStatus")
    public AppServeDataResponse<TrayConveyStatusVo> queryTrayConveyStatus(@RequestParam("conveyId") @NotBlank(message = "输送点位ID不能为空") String conveyId) {
        return trayConveyLocationService.queryTrayConveyStatus(conveyId);
    }

    /**
     * 下载托盘输送点位数据
     * @param request 查询参数
     * @param response 响应对象
     */
    @PostMapping("downloadTrayConveyLocation")
    public void downLoadTrayConveyLocation(HttpServletResponse response, @RequestBody QueryTrayConveyLocationReq request) {
        trayConveyLocationService.downLoadTrayConveyLocation(response, request);
    }

}
