package com.prolog.eis.controller.wcs;

import com.prolog.eis.core.dto.rcs.RcsSendBindReqDto;
import com.prolog.eis.dto.wcs.CallbackLayerDTO;
import com.prolog.eis.service.inbound.BizInboundTaskService;
import com.prolog.eis.service.outbound.BizOutboundTaskService;
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 org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author dengj
 * @version 1.0
 * @date 2023/1/10 18:01
 */
@RequiredArgsConstructor
@RestController
@Api(tags = "MCS接口服务")
@RequestMapping(value = "/api/v1/eis")
public class RouterController {

    private final BizInboundTaskService inboundTaskService;
    private final BizOutboundTaskService outboundTaskService;



    /**
     * 二次分配点
     *
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "入库二次分配点", notes = "入库二次分配点")
    @RequestMapping(method = RequestMethod.POST, value = "/allocationRoadway")
    @InterfaceMethod(key = "入库二次分配点", name = "入库二次分配点", type = InterfaceType.Receive)
    public RestMessage allocationRoadwayReq(@RequestBody @Valid CallbackLayerDTO callbackLayerDTO) {
        try {
            return RestMessage.newInstance(true,null,inboundTaskService.allocationRoadwayReq(callbackLayerDTO));
        }catch (Exception e) {
            return RestMessage.newInstance(false,e.getMessage());
        }
    }


    @ApiOperation(value = "路径中间节点触发接口", notes = "路径中间节点触发接口")
    @RequestMapping(method = RequestMethod.POST, value = "/sendMsg")
    @InterfaceMethod(key = "路径中间节点触发接口", name = "路径中间节点触发接口", type = InterfaceType.Receive)
    public RestMessage sendMsg(@RequestBody @Valid RcsSendBindReqDto rcsSendBindReqDto) {
        try {
            outboundTaskService.sendLedMsg(rcsSendBindReqDto);
            return RestMessage.newInstance(true,null);
        }catch (Exception e) {
            return RestMessage.newInstance(false,e.getMessage());
        }
    }

}
