package com.ywt.glasses.controllers.mg;

import com.ywt.glasses.api.mg.order.*;
import com.ywt.glasses.api.order.GetOrderDetailRemarkRequest;
import com.ywt.glasses.api.order.GetOrderDetailRequest;
import com.ywt.glasses.api.order.GetOrderDetailResponse;
import com.ywt.glasses.constants.ConstantRightDisplayDef;
import com.ywt.glasses.core.BaseResponse;
import com.ywt.glasses.core.DataResponse;
import com.ywt.glasses.core.MGRight;
import com.ywt.glasses.core.MGRightTypeDef;
import com.ywt.glasses.service.AreaService;
import com.ywt.glasses.service.GoodsOrdersService;
import com.ywt.glasses.service.MgGoodsOrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author daiyihua
 * @desc 客户端下单相关接口
 */
@MGRight
@Api(description = "客户端下单相关接口")
@RestController
@RequestMapping(value = {"/mg/order"}, method = RequestMethod.POST)
public class MgOrderController {

    private static final Logger logger = LoggerFactory.getLogger(MgOrderController.class);

    @Autowired
    private GoodsOrdersService goodsOrdersService;

    @Autowired
    private MgGoodsOrdersService mgGoodsOrdersService;

    @Autowired
    private AreaService areaService;

    @MGRight(menuCode = {"/mg/order/getGoodsList"}, type = MGRightTypeDef.Menu | MGRightTypeDef.Logined)
    @ApiOperation(value = "获取商品列表接口")
    @RequestMapping(value = "/getGoodsList")
    public BaseResponse getGoodsList(@RequestBody GetGoodsListRequest request) throws Exception {
        return mgGoodsOrdersService.getGoodsList(request);
    }

    @MGRight(menuCode = {"/mg/order/getOrderDetail"}, type = MGRightTypeDef.Menu | MGRightTypeDef.Logined)
    @ApiOperation(value = "得到订单详情接口")
    @RequestMapping(value = "/getOrderDetail")
    public DataResponse<GetOrderDetailResponse> getOrderDetail(@RequestBody GetOrderDetailRequest request) throws Exception {
        return goodsOrdersService.getOrderDetail(request);
    }

    @MGRight(menuCode = {"/mg/order/createOrder"}, type = MGRightTypeDef.Menu | MGRightTypeDef.Logined)
    @ApiOperation(value = "下单接口")
    @RequestMapping(value = "/createOrder")
    public DataResponse<CreateOrderResponse> createOrder(@RequestBody CreateOrderRequest request) throws Exception {
        return mgGoodsOrdersService.createOrder(request);
    }

    @MGRight(need = false)
    @ApiOperation(value = "微信支付回调接口")
    @RequestMapping(value = {"/paymentCallback"})
    public BaseResponse paymentCallback(@RequestBody PaymentCallbackRequest request) {
        return mgGoodsOrdersService.paymentCallback(request);
    }

    @MGRight(menuCode = {ConstantRightDisplayDef.GOODS_ORDERS_CONFIRM_PAYMENT}, type = MGRightTypeDef.Right)
    @ApiOperation(value = "确认支付接口")
    @RequestMapping(value = {"/confirmPayment"})
    public BaseResponse confirmPayment(@RequestBody ConfirmPaymentRequest request) throws Exception {
        return mgGoodsOrdersService.confirmPayment(request);
    }

    @MGRight(menuCode = {ConstantRightDisplayDef.GOODS_ORDERS_REFUND_ORDER}, type = MGRightTypeDef.Right)
    @ApiOperation(value = "退款接口")
    @RequestMapping({"/refundOrder"})
    BaseResponse refundOrder(@RequestBody RefundOrderRequest request) throws Exception {
        return mgGoodsOrdersService.refundOrder(request);
    }

    @MGRight(need = false)
    @ApiOperation(value = "退款回调接口")
    @RequestMapping(value = {"/refundCallback"})
    public BaseResponse refundCallback(@RequestBody RefundCallbackRequest request) {
        return mgGoodsOrdersService.refundCallback(request);
    }

    /**
     * 采用 {@link GoodsOrderController  #amountList(AmountListRequest)}
     *
     * @param request {@link AmountListRequest}
     * @return {@link BaseResponse}
     * @throws Exception
     */
    @Deprecated
    @ApiOperation(value = "对账展示")
    @MGRight(menuCode = {"/amountList"}, type = MGRightTypeDef.Menu | MGRightTypeDef.Logined)
    @RequestMapping({"/amountList"})
    BaseResponse amountList(AmountListRequest request) throws Exception {
        return goodsOrdersService.amountList(request);
    }

    /**
     * 采用 {@link GoodsOrderController #downloadAmountList(AmountListRequest)}
     *
     * @param request {@link AmountListRequest}
     * @return {@link BaseResponse}
     * @throws Exception
     */
    @Deprecated
    @ApiOperation(value = "对账excel下载")
    @MGRight(menuCode = {"/downloadBillOrderList"}, type = MGRightTypeDef.Menu | MGRightTypeDef.Logined)
    @RequestMapping(value = {"/downloadBillOrderList"}, method = RequestMethod.GET)
    public void downloadBillOrderList(AmountListRequest request, HttpServletResponse httpServletResponse) {
        goodsOrdersService.downloadBillOrderList(request, httpServletResponse);
    }

    @ApiOperation(value = "地区列表")
    @MGRight(menuCode = {"/getAreaList"}, type = MGRightTypeDef.Menu | MGRightTypeDef.Logined)
    @RequestMapping(value = {"/getAreaList"}, method = RequestMethod.GET)
    public BaseResponse getAreaList() throws Exception {
        return areaService.getAreaList();
    }

    @ApiOperation(value = "修改取货方式")
    @MGRight(menuCode = {"/addOrUpdateGetChannel"}, type = MGRightTypeDef.Menu | MGRightTypeDef.Logined)
    @RequestMapping(value = {"/addOrUpdateGetChannel"})
    public BaseResponse addOrUpdateGetChannel(@RequestBody addOrUpdateGetChannelRequest request) {
        return mgGoodsOrdersService.addOrUpdateGetChannel(request);
    }

    @ApiOperation(value = "得到订单商品备注接口")
    @RequestMapping(value = "/getDetailRemark")
    public DataResponse getDetailRemark(@RequestBody GetOrderDetailRemarkRequest request) throws Exception {
        return goodsOrdersService.getGoodsRemark(request.getOrderId(), request.getDetailId());
    }

    @MGRight(menuCode = {"/saveDetailRemark"}, type = MGRightTypeDef.Menu | MGRightTypeDef.Logined)
    @ApiOperation(value = "订单商品备注")
    @RequestMapping(value = "/saveDetailRemark")
    public BaseResponse saveDetailRemark(@RequestBody com.ywt.glasses.api.order.OrderDetailVo request) throws Exception {
        return goodsOrdersService.saveDetailRemark(request);
    }

}
