package com.ywt.controllers.api;

import com.ywt.core.BaseResponse;
import com.ywt.core.DataResponse;
import com.ywt.core.MGRight;
import com.ywt.core.MGRightTypeDef;
import com.ywt.params.api.order.*;
import com.ywt.service.AreaService;
import com.ywt.service.GoodsOrdersService;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author daiyihua
 * @desc 小程序眼镜订单相关接口
 */
@RestController
@RequestMapping(value = {"/api/order"}, method = RequestMethod.POST)
public class OrderController {

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

    @Autowired
    private GoodsOrdersService goodsOrdersService;

    @Autowired
    private AreaService areaService;

    @ApiOperation(value = "得到订单详情接口")
    @RequestMapping(value = "/getOrderDetail")
    public DataResponse<GetOrderDetailResponse> getOrderDetail(@RequestBody GetOrderDetailRequest request) throws Exception {
        return goodsOrdersService.getOrderDetail(request);
    }

    @ApiOperation(value = "得到眼镜订单列表")
    @RequestMapping(value = "/getGoodsOrdersList")
    public DataResponse getGoodsOrdersList(@RequestBody GetGoodsOrdersListRequest request) throws Exception {
        return goodsOrdersService.getGoodsOrdersList(request);
    }

    @ApiOperation(value = "检查订单")
    @RequestMapping(value = "/checkOrders")
    public BaseResponse checkOrders(@RequestBody PayOrderRequest request) throws Exception {
        return goodsOrdersService.checkOrders(request);
    }

    @ApiOperation(value = "保存邮寄地址")
    @RequestMapping(value = "/saveMailAddress")
    public BaseResponse saveMailAddress(@RequestBody SaveMailAddressRequest request) throws Exception {
        return goodsOrdersService.saveMailAddress(request);
    }

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

}
