package com.ruoyi.controller;

import com.ruoyi.annotations.UserLoginToken;
import com.ruoyi.common.page.PageResult;
import com.ruoyi.controller.req.*;
import com.ruoyi.controller.resp.MallOrderDetailResp;
import com.ruoyi.controller.resp.MallOrderPageResp;
import com.ruoyi.frequency.mallorder.service.MallOrderService;
import com.ruoyi.frequency.mallrefund.entity.MallRefund;
import com.ruoyi.response.ResponseData;
import com.ruoyi.vo.PayVo;
import com.ruoyi.vo.RyController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@CrossOrigin
@RestController
@RequestMapping("/api/mallOrder")
@Api(tags = "商城")
public class ApiMallOrderController extends RyController {


    @Autowired
    private MallOrderService orderService;

    @UserLoginToken
    @RequestMapping(value = "/settlement", method = RequestMethod.POST)
    @ApiOperation(value = "订单结算")
    public ResponseData<PayVo> settlement(@RequestBody MallSettlementReq req) {
        return ResponseData.success(orderService.settlement(req,getUserVo()));
    }

    @UserLoginToken
    @RequestMapping(value = "/createOrder", method = RequestMethod.POST)
    @ApiOperation(value = "创建订单")
    public ResponseData createOrder(@RequestBody CreateOrderReq req) {
        return orderService.createOrder(req,getUserVo());
    }

    @UserLoginToken
    @RequestMapping(value = "/orderPage", method = RequestMethod.POST)
    @ApiOperation(value = "商城订单列表")
    public ResponseData<PageResult<MallOrderPageResp>> orderPage(@RequestBody MallOrderPageReq req) {
        return orderService.orderPage(req, getUserVo());
    }

    @UserLoginToken
    @RequestMapping(value = "/orderDetail", method = RequestMethod.POST)
    @ApiOperation(value = "商城订单列表_详情")
    public ResponseData<MallOrderDetailResp> orderDetail(@RequestBody @NotNull(message = "订单id不能为空") Long orderId) {
        return orderService.orderDetail(orderId, getUserVo());

    }

    @UserLoginToken
    @RequestMapping(value = "/orderPay", method = RequestMethod.POST)
    @ApiOperation(value = "商城订单列表——付款")
    public ResponseData orderPay(@RequestBody MallOrderPayReq req) {
        return orderService.orderPay(req, getUserVo());

    }

    @UserLoginToken
    @RequestMapping(value = "/orderCancel", method = RequestMethod.POST)
    @ApiOperation(value = "商城订单列表——取消")
    public ResponseData orderCancel(@RequestBody @NotNull(message = "订单id不能为空") Long orderId) {
        return orderService.orderCancel(orderId, getUserVo());
    }

    @UserLoginToken
    @RequestMapping(value = "/orderRefund", method = RequestMethod.POST)
    @ApiOperation(value = "商城订单列表——退款")
    public ResponseData orderRefund(@RequestBody @NotNull(message = "订单id不能为空") Long orderId) {
        return orderService.orderRefund(orderId, getUserVo());
    }

    @UserLoginToken
    @RequestMapping(value = "/orderConfirm", method = RequestMethod.POST)
    @ApiOperation(value = "商城订单列表——确认收货")
    public ResponseData orderConfirm(@RequestBody MallOrderConfirmReq req) {
        return orderService.orderConfirm(req, getUserVo());

    }

    @UserLoginToken
    @RequestMapping(value = "/orderAfterApply", method = RequestMethod.POST)
    @ApiOperation(value = "商城订单列表——售后申请")
    public ResponseData orderAfterApply(@RequestBody ApplyAfterSalesReq req) {
        return orderService.orderAfterApply(req, getUserVo());

    }
    @UserLoginToken
    @RequestMapping(value = "/orderAfterDetail", method = RequestMethod.POST)
    @ApiOperation(value = "商城订单列表——售后——详情")
    public ResponseData<MallRefund> orderAfterDetail(@RequestBody Long orderId) {
        return orderService.orderAfterDetail(orderId, getUserVo());

    }
    @UserLoginToken
    @RequestMapping(value = "/orderAfterRevokeApply", method = RequestMethod.POST)
    @ApiOperation(value = "商城订单列表——售后——撤销申请")
    public ResponseData orderAfterRevokeApply(@RequestBody Long refundId) {
        return orderService.orderAfterRevokeApply(refundId, getUserVo());

    }

    @UserLoginToken
    @RequestMapping("/customerDeliverGoods")
    @ApiOperation(value = "商城订单列表——售后——用户发货(申请售后成功)")
    public ResponseData customerDeliverGoods(@RequestBody CustomerDeliverGoodsReq req) {
        return orderService.customerDeliverGoods(req);
    }


    @UserLoginToken
    @RequestMapping(value = "/evaluate", method = RequestMethod.POST)
    @ApiOperation(value = "用户评价")
    public ResponseData evaluate(@RequestBody MallEvaluateReq req) {
        return orderService.evaluate(req,getUserVo());
    }

    @UserLoginToken
    @RequestMapping(value = "/onceAgainCreateOrder", method = RequestMethod.POST)
    @ApiOperation(value = "再次下单")
    public ResponseData onceAgainCreateOrder(@RequestBody OnceAgainCreateOrderReq req) {
        return orderService.onceAgainCreateOrder(req,getUserVo());
    }
}
