package com.prolog.cs.biz.outbound.controller;

import com.prolog.cs.biz.outbound.model.dto.WorkStageTransferDTO;
import com.prolog.cs.biz.outbound.model.vo.WorkStageVO;
import com.prolog.cs.biz.outbound.service.WavesService;
import com.prolog.cs.biz.outbound.service.WorkStageService;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "波次")
@RestController
@RequestMapping("/workstage")
public class WorkStageController {
    @Autowired
    private WavesService wavesService;

    @Autowired
    private WorkStageService workStageService;

    @UserLog
    @ApiOperation(value = "波次暂存区预占查询")
    @GetMapping("/")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "warehouseId", value = "仓库id", required = true),
            @ApiImplicitParam(name = "waveId", value = "波次id"),
            @ApiImplicitParam(name = "billId", value = "订单id"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true)})
    public RestMessage<Page<WorkStageVO>> getWorkStage(String warehouseId,
                                                       String waveId,
                                                       String billId,
                                                       Integer pageNum,
                                                       Integer pageSize
    ) {
        return RestMessage.success("操作成功", wavesService.getWaveWorkStage(warehouseId,
                waveId, billId, pageNum, pageSize));
    }

    @UserLog
    @ApiOperation(value = "集货区转移")
    @PostMapping("/transfer")
    public RestMessage<Boolean> transfer(@RequestBody WorkStageTransferDTO workStageTransferDTO) {
        return workStageService.transfer(workStageTransferDTO);
    }

    @UserLog
    @ApiOperation(value = "释放集货区")
    @GetMapping("/release")
    public RestMessage<?> releaseWorkStage(String billGroupId,String warehouseId) {
        long result = workStageService.releaseWorkStage(billGroupId);
        return RestMessage.success("操作成功", result);
    }

}
