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.stackerLocation.AddManyStackerLocationsReq;
import org.wcs.model.dto.serve.stackerLocation.AddStackerLocationReq;
import org.wcs.model.dto.serve.stackerLocation.QueryStackerLocationReq;
import org.wcs.model.dto.serve.stackerLocation.UpdateStackerLocationReq;
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.stackerLocation.QueryStackerLocationVo;
import org.wcs.serve.service.intf.IStackerLocationService;

import java.util.List;

/**
 * 堆垛机相关控制器
 */
@RestController
@RequestMapping("/app/stackerLocation")
@ResponseBody
@RequiredArgsConstructor
public class StackerLocationController {

    private final IStackerLocationService stackerLocationService;

    /**
     * 分页查询库位信息
     * @param request 查询参数
     * @param pageSize 分页大小
     * @param pageIndex 页面序号
     * @return 查询结果
     */
    @PostMapping("queryStackerLocation")
    public AppServeDataResponse<PageDataResponse<QueryStackerLocationVo>> queryStackerLocation(@RequestBody QueryStackerLocationReq request, @RequestParam("pageSize") Integer pageSize, @RequestParam("pageIndex") Integer pageIndex) {
        return stackerLocationService.queryStackerLocation(request, pageSize, pageIndex);
    }

    /**
     * 下载堆垛机货位信息
     * @param request 请求参数
     * @param response 响应
     */
    @PostMapping("downloadStackerLocation")
    public void downloadStackerLocation(HttpServletResponse response, @RequestBody QueryStackerLocationReq request) {
        stackerLocationService.downloadStackerLocation(response, request);
    }

    /**
     * 新增堆垛机库位信息
     * @param request 新增参数
     * @return 新增结果
     */
    @PostMapping("addStackerLocation")
    public AppServeResponse addStackerLocation(@RequestBody @Validated AddStackerLocationReq request) {
        return stackerLocationService.addStackerLocation(request);
    }

    /**
     * 批量新增堆垛机库位信息
     * @param request 新增参数
     * @return 新增结果
     */
    @PostMapping("addStackerLocations")
    public AppServeResponse addStackerLocations(@RequestBody @Validated AddManyStackerLocationsReq request) {
        return stackerLocationService.addStackerLocations(request);
    }

    /**
     * 修改堆垛机库位信息
     * @param request 修改参数
     * @return 修改结果
     */
    @PostMapping("updateStackerLocation")
    public AppServeResponse updateStackerLocation(@RequestBody @Validated UpdateStackerLocationReq request) {
        return stackerLocationService.updateStackerLocation(request);
    }

    /**
     * 根据巷道号查询堆垛机库位信息
     * @param laneId 巷道号
     * @return 查询结果
     */
    @GetMapping("queryStackerLocationListByStackerIdAndLaneId")
    public AppServeDataResponse<List<QueryStackerLocationVo>> queryStackerLocationListByStackerIdAndLaneId(@RequestParam @NotNull(message = "设备号不能为空") Integer stackerId, @RequestParam @NotNull(message = "巷道号不能为空") Integer laneId) {
        return stackerLocationService.queryStackerLocationListByStackerIdAndLaneId(stackerId, laneId);
    }

    /**
     * 查询堆垛机库位巷道列表
     * @param stackerId 设备号
     * @return 巷道列表
     */
    @GetMapping("queryStackerLocationLaneList")
    public AppServeDataResponse<List<Integer>> queryStackerLocationLaneList(@RequestParam @NotNull(message = "设备号不能为空") Integer stackerId) {
        return stackerLocationService.queryStackerLocationLaneList(stackerId);
    }

    @GetMapping("queryStackerLocationStackerIdList")
    public AppServeDataResponse<List<Integer>> queryStackerLocationStackerIdList() {
        return stackerLocationService.queryStackerLocationStackerIdList();
    }

}
