package com.prolog.eis.controller.wcs;


import com.prolog.eis.dto.inbound.InBoundDto;
import com.prolog.eis.dto.wcs.WcsCarDto;
import com.prolog.eis.dto.wcs.WcsCarryBackDto;
import com.prolog.eis.dto.wcs.WcsGirdDto;
import com.prolog.eis.service.logic.WcsTaskService;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.fx.inf.core.InterfaceType;
import com.prolog.fx.inf.core.annotation.InterfaceMethod;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RequiredArgsConstructor
@RestController
@Slf4j
@Validated
@Api(tags = "Wcs接口服务")
@RequestMapping(value = "api/v1/wcs")
public class WcsController {

    private final WcsTaskService wcsTaskService;

    @ApiOperation(value = "WCS落格回告", notes = "WCS落格回告")
    @PostMapping(value = "/carryFinishBack")
    @InterfaceMethod(key = "WCS落格回告", name = "WCS->EIS落格回告", type = InterfaceType.Receive)
    public RestMessage carryFinishBack(@Valid @RequestBody WcsCarryBackDto wcsCarryBackDto) {
        try {
            wcsTaskService.carryFinishBack(wcsCarryBackDto);
            return RestMessage.success("请求成功", null);
        } catch (Exception e) {
            log.error("WCS落格回告异常:" + e.getMessage(), e);
            return RestMessage.error("请求异常" + e.getMessage());
        }
    }


    @ApiOperation(value = "WCS格口状态上报", notes = "WCS格口状态上报")
    @PostMapping(value = "/girdStatusSync")
    @InterfaceMethod(key = "WCS格口状态上报", name = "WCS->EIS格口状态上报", type = InterfaceType.Receive)
    public RestMessage girdStatusSync(@Valid @RequestBody WcsGirdDto wcsGirdDto) {
        try {
            wcsTaskService.girdStatusSync(wcsGirdDto);
            return RestMessage.success("请求成功", null);
        } catch (Exception e) {
            log.error("WCS分拨任务回告异常:" + e.getMessage(), e);
            return RestMessage.error("请求异常" + e.getMessage());
        }
    }


    @ApiOperation(value = "WCS小车运行状态上报", notes = "WCS小车运行状态上报")
    @PostMapping(value = "/carStatusSync")
    @InterfaceMethod(key = "WCS小车运行状态上报", name = "WCS->EIS小车运行状态上报", type = InterfaceType.Receive)
    public RestMessage carStatusSync(@Valid @RequestBody WcsCarDto wcsCarDto) {
        try {
            wcsTaskService.carStatusSync(wcsCarDto);
            return RestMessage.success("请求成功", null);
        } catch (Exception e) {
            log.error("WCS分拨任务回告异常:" + e.getMessage(), e);
            return RestMessage.error("请求异常" + e.getMessage());
        }
    }

}
