package com.yami.shop.platform.controller;

import com.yami.shop.bean.po.SMOrderPo;
import com.yami.shop.common.exception.GlobalException;
import com.yami.shop.common.util.R;
import com.yami.shop.service.OrderService;
import com.yami.shop.service.hb.IHBOrderService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
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;

@RestController
@RequestMapping("/sm/order")
@AllArgsConstructor
@Log4j2
public class SMOrderController {

    private final OrderService orderService;
    private final IHBOrderService hbOrderService;

    @PostMapping("/addSMOrder")
    @ApiOperation(value = "addSMOrder")
    public R<?> addSMOrder(@RequestBody SMOrderPo orderPo) {
        if (orderPo.getOrderItems() == null){
            throw new GlobalException("订单项不能为空");
        }
        String orderNumber = orderService.addSMOrder(orderPo);
        hbOrderService.createOrderAsync(orderNumber);
        return R.SUCCESS();
    }
}