package com.prolog.upcloud.base.wh.operate.controller;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.utils.AssertUtils;
import com.prolog.upcloud.base.wh.operate.controller.common.BaseController;
import com.prolog.upcloud.base.wh.operate.model.WmsCargoChange;
import com.prolog.upcloud.base.wh.operate.service.CargoChangeService;
import com.prolog.upcloud.base.wh.operate.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 货主转换
 *
 * @author wujunjie
 */
@Api(tags = "货主转换")
@RestController
@RequestMapping("stock-change")
@RequiredArgsConstructor
public class ChangeController extends BaseController {

    @Resource
    private CargoChangeService cargoChangeService;

    @GetMapping("v1/source-heads")
    @ApiOperation(value = "提取源单列表")
    public RestMessage<Page<OmsCnsConversionListVO>> getSourceHeaderList(@RequestParam("warehouseId") String warehouseId) {
        startPage();
        return success(cargoChangeService.getSourceHeaderList(warehouseId));
    }

    @PostMapping("v1/source-trans")
    @ApiOperation(value = "源单转换WMS单据")
    @ApiImplicitParam(name = "billNos", value = "源单号集合", required = true, dataType = "String", allowMultiple = true)
    public RestMessage changeSourceList(@RequestBody @Validated CargoChangeSourceParamsVO paramsVO) {
        cargoChangeService.changeSourceList(paramsVO.getBillnos());
        return success();
    }


    @PostMapping("v1/change")
    @ApiOperation(value = "货权变更")
    @ApiImplicitParam(name = "headerIds", value = "头表ID集合", required = true, dataType = "String", allowMultiple = true)
    public RestMessage change(@RequestBody List<WmsCargoChange> paramsVO) {
        AssertUtils.notNull(paramsVO, "请选择数据");
        cargoChangeService.change(paramsVO);
        return success();
    }

    @GetMapping("v1/heads")
    @ApiOperation(value = "获取货权变更头表列表")
    public RestMessage<Page<WmsCargoChangeListVO>> getCargoChangeList(CargoChangeQueryVO queryVO) {
        startPage();
        return success(cargoChangeService.getCargoChangeList(queryVO));
    }

    @GetMapping("v1/details")
    @ApiOperation(value = "获取货权变更明细列表")
    public RestMessage<Page<WmsCargoChangeDetailListVO>> getCargoChangeDetailList(String headerId) {
        startPage();
        return success(cargoChangeService.getCargoChangeDetailList(headerId));
    }
}
