package com.wms_main.controller.ycwms;


import com.wms_main.model.dto.request.ycwms.*;
import com.wms_main.model.dto.response.ycwms.YcwmsResponse;
import com.wms_main.repository.utils.StringUtils;
import com.wms_main.service.controller.IYcwmsControllerService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 和亚驰仓库对接的接口
 */
@RestController
@ResponseBody
@CrossOrigin
@RequiredArgsConstructor
@RequestMapping("/ycwms")
public class YcwmsController {


    private final IYcwmsControllerService ycwmsControllerService;

    /**
     * 接收亚驰 WMS 发来的 入库单
     * @param request 请求数据
     * @return 返回
     */
    @PostMapping("/orderIn")
    public YcwmsResponse<Object> orderIn(@RequestBody OrderInReq request) {
        return ycwmsControllerService.orderIn(request);
    }

    @PostMapping("/orderOut")
    public YcwmsResponse<Object> orderOut(@RequestBody OrderOutReq request) {
        return ycwmsControllerService.orderOut(request);
    }

    @PostMapping("/stock")
    public YcwmsResponse<List<StockResp>> stock(@RequestBody StockReq request) {
        return ycwmsControllerService.stock(request);
    }

    @GetMapping("/getAvailPercent")
    public YcwmsResponse<Object> getAvailPercent(@RequestParam(value = "equipmentId") String equipmentId) {
        return ycwmsControllerService.getAvailPercent(equipmentId);
    }

    @PostMapping("/localQuery")
    public YcwmsResponse<List<StockResp>> localQuery(@RequestBody LocalOrderReq request) {
        return ycwmsControllerService.localQuery(request);
    }

    @PostMapping("/getOutLocation")
    public YcwmsResponse<Object> getOutLocation(@RequestBody OrderOutReq request) {
        String outLoc = ycwmsControllerService.getLocByGoodsId(request.getGoodsId());
        if (StringUtils.isEmpty(outLoc)) {
            return YcwmsResponse.error("查询库存为空", null);
        } else {
            return YcwmsResponse.success(outLoc);
        }
    }

    @PostMapping("/localOut")
    public YcwmsResponse<Object> localOut(@RequestBody List<String> vehicleNos) {
        return ycwmsControllerService.localOut(vehicleNos);
    }
}
