package com.bonus.core.order.mobile.controller;

import com.bonus.common.core.domain.R;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.constant.RetCodeEnum;
import com.bonus.core.common.utils.LogUtil;
import com.bonus.core.order.common.dto.RequestHeaderDTO;
import com.bonus.core.order.mobile.business.OrderPlaceMobileBusiness;
import com.bonus.core.order.mobile.dto.OrderReserveMealTotalDTO;
import com.bonus.core.order.mobile.vo.OrderPayMobileVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping({"/api/v2/mobile/order"})
@Api(
   value = "mobileOrderPlace",
   tags = {"移动端下单接口"}
)
public class OrderPlaceMobileController {
   private static final Logger log = LoggerFactory.getLogger(OrderPlaceMobileController.class);
   @Autowired
   protected OrderPlaceMobileBusiness orderPlaceMobileBusiness;

//   @PostMapping({"/curr/meal/add"})
//   @ApiOperation(
//      value = "当餐下单",
//      notes = "cmt-当餐下单"
//   )
//   public LeResponse<OrderPayMobileVO> addCurrentMealOrder(@RequestHeader Map<String, String> headers, @RequestBody LeRequest<OrderCurrMealTotalDTO> request) {
//      long startTime = System.currentTimeMillis();
//      RequestHeaderDTO headerDTO = RequestHeaderDTO.of(headers);
//      OrderCurrMealTotalDTO currMealTotalDTO = (OrderCurrMealTotalDTO)request.getContent();
//      currMealTotalDTO.setCustId(headerDTO.getCustId());
//      OrderPayMobileVO mobileVO = this.orderPlaceMobileBusiness.addCurrentMealOrder(headerDTO, currMealTotalDTO);
//      LogUtil.info("[当餐下单]支付耗时：{}", System.currentTimeMillis() - startTime, mobileVO);
//      if (CollectionUtils.isNotEmpty(mobileVO.getGoodIdSet())) {
//         return LeResponse.fail(RetCodeEnum.MENU_EXCEED_SURPLUS_NUM, mobileVO);
//      } else {
//         return !mobileVO.success() ? LeResponse.fail(mobileVO.getCode(), mobileVO.getMsg(), mobileVO) : LeResponse.succ(mobileVO);
//      }
//   }

   @PostMapping({"/reserve/meal/add"})
   @ApiOperation(
      value = "预订餐下单",
      notes = "cmt-预订餐下单"
   )
   public R<OrderPayMobileVO> addReserveMealOrder(@RequestHeader Map<String, String> headers, @RequestBody OrderReserveMealTotalDTO reserveMealDTO) {
      long startTime = System.currentTimeMillis();
      RequestHeaderDTO headerDTO = RequestHeaderDTO.of(headers);
      reserveMealDTO.setCustId(headerDTO.getCustId());
      OrderPayMobileVO mobileVO = this.orderPlaceMobileBusiness.addReserveMealOrder(headerDTO, reserveMealDTO);
      LogUtil.info("[预订餐下单]支付耗时", System.currentTimeMillis() - startTime, mobileVO);
      if (CollectionUtils.isNotEmpty(mobileVO.getGoodIdSet())) {
         return R.fail(mobileVO, RetCodeEnum.MENU_EXCEED_SURPLUS_NUM.getDesc());
      } else {
         return !mobileVO.success() ? R.fail(mobileVO, mobileVO.getMsg()) : R.ok(mobileVO);
      }
   }

//   @PostMapping({"/book/meal/add"})
//   @ApiOperation(
//      value = "报餐下单",
//      notes = "cmt-报餐下单"
//   )
//   public LeResponse<OrderPayMobileVO> addBookMealOrder(@RequestHeader Map<String, String> headers, @RequestBody LeRequest<OrderBookMealTotalDTO> request) {
//      long startTime = System.currentTimeMillis();
//      RequestHeaderDTO headerDTO = RequestHeaderDTO.of(headers);
//      OrderBookMealTotalDTO bookMealDTO = (OrderBookMealTotalDTO)request.getContent();
//      bookMealDTO.setCustId(headerDTO.getCustId());
//      OrderPayMobileVO mobileVO = this.orderPlaceMobileBusiness.addBookMealOrder(headerDTO, bookMealDTO);
//      LogUtil.info("[报餐下单]支付耗时", System.currentTimeMillis() - startTime, mobileVO);
//      return !mobileVO.success() ? LeResponse.fail(mobileVO.getCode(), mobileVO.getMsg(), mobileVO) : LeResponse.succ(mobileVO);
//   }
//
//   @PostMapping({"/shop/add"})
//   @ApiOperation(
//      value = "商城下单",
//      notes = "cmt-商城下单"
//   )
//   public LeResponse<OrderPayMobileVO> addShopMealOrder(@RequestHeader Map<String, String> headers, @RequestBody LeRequest<OrderShopDTO> request) {
//      long startTime = System.currentTimeMillis();
//      RequestHeaderDTO headerDTO = RequestHeaderDTO.of(headers);
//      OrderShopDTO orderShopDTO = (OrderShopDTO)request.getContent();
//      orderShopDTO.setCustId(headerDTO.getCustId());
//      OrderPayMobileVO mobileVO = this.orderPlaceMobileBusiness.addShopMealOrder(headerDTO, orderShopDTO);
//      LogUtil.info("[商城下单]支付耗时", System.currentTimeMillis() - startTime, mobileVO);
//      if (CollectionUtils.isNotEmpty(mobileVO.getGoodIdSet())) {
//         return LeResponse.fail(RetCodeEnum.MENU_EXCEED_SURPLUS_NUM, mobileVO);
//      } else {
//         return !mobileVO.success() ? LeResponse.fail(mobileVO.getCode(), mobileVO.getMsg(), mobileVO) : LeResponse.succ(mobileVO);
//      }
//   }
//
//   @PostMapping({"/scan/add"})
//   public LeResponse<OrderPayMobileVO> addScanOrder(@RequestHeader Map<String, String> headers, @RequestBody LeRequest<OrderMobileScanDTO> request) {
//      long startTime = System.currentTimeMillis();
//      RequestHeaderDTO headerDTO = RequestHeaderDTO.of(headers);
//      OrderMobileScanDTO orderShopDTO = (OrderMobileScanDTO)request.getContent();
//      orderShopDTO.setCustId(headerDTO.getCustId());
//      OrderPayMobileVO mobileVO = this.orderPlaceMobileBusiness.addSacnOrder(headerDTO, orderShopDTO);
//      LogUtil.info("[到店扫码下单]支付耗时", System.currentTimeMillis() - startTime, mobileVO);
//      return mobileVO.success() ? LeResponse.succ(mobileVO) : LeResponse.fail(mobileVO.getCode(), mobileVO.getMsg(), mobileVO);
//   }
//
//   @PostMapping({"/pay/by/orderId"})
//   @ApiOperation(
//      value = "根据订单id支付",
//      notes = "cmt-根据订单id支付"
//   )
//   public LeResponse<OrderPayMobileVO> orderPayByOrderId(@RequestHeader Map<String, String> headers, @RequestBody LeRequest<OrderPayMobileDTO> request) {
//      long startTime = System.currentTimeMillis();
//      RequestHeaderDTO headerDTO = RequestHeaderDTO.of(headers);
//      OrderPayMobileDTO orderPayDTO = (OrderPayMobileDTO)request.getContent();
//      orderPayDTO.setCustId(headerDTO.getCustId());
//      OrderPayMobileVO mobileVO = this.orderPlaceMobileBusiness.orderPayByOrderId(headerDTO, orderPayDTO);
//      LogUtil.info("[根据订单id支付]支付耗时", System.currentTimeMillis() - startTime, mobileVO);
//      return !mobileVO.success() ? LeResponse.fail(mobileVO.getCode(), mobileVO.getMsg(), mobileVO) : LeResponse.succ(mobileVO);
//   }
//
//   @PostMapping({"/mixPay/by/orderId"})
//   @ApiOperation(
//      value = "根据交易id混合支付",
//      notes = "根据交易id混合支付"
//   )
//   public LeResponse<OrderPayMobileVO> mixPayByTradeId(@RequestHeader Map<String, String> headers, @RequestBody LeRequest<OrderMixPayMobileDTO> request) {
//      long startTime = System.currentTimeMillis();
//      RequestHeaderDTO headerDTO = RequestHeaderDTO.of(headers);
//      OrderMixPayMobileDTO orderMixPayMobileDTO = (OrderMixPayMobileDTO)request.getContent();
//      orderMixPayMobileDTO.setCustId(headerDTO.getCustId());
//      OrderPayMobileVO mobileVO = this.orderPlaceMobileBusiness.orderMixPayByTradeId(headerDTO, orderMixPayMobileDTO);
//      LogUtil.info("[根据交易id混合支付]支付耗时", System.currentTimeMillis() - startTime, mobileVO);
//      return !mobileVO.success() ? LeResponse.fail(mobileVO.getCode(), mobileVO.getMsg(), mobileVO) : LeResponse.succ(mobileVO);
//   }
//
//   @PostMapping({"/pre-book/add"})
//   public LeResponse<OrderPayMobileVO> addPreBook(@RequestHeader Map<String, String> headers, @RequestBody LeRequest<OrderPreBookAddDTO> request) {
//      RequestHeaderDTO headerDTO = RequestHeaderDTO.of(headers);
//      OrderPreBookAddDTO addDTO = (OrderPreBookAddDTO)request.getContent();
//      addDTO.setCustId(headerDTO.getCustId());
//      this.orderPlaceMobileBusiness.orderPreBookAdd(headerDTO, addDTO);
//      return LeResponse.succ();
//   }
}
