package org.jeecg.modules.xcx.order.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.TokenUtils;
import org.jeecg.modules.xcx.goods.req.EditLeaseNumReq;
import org.jeecg.modules.xcx.order.req.*;
import org.jeecg.modules.xcx.order.service.IOrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;

@Api(tags = "订单接口")
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private IOrderService orderService;

    @ApiOperation(value = "分页", notes = "分页")
    @GetMapping("/page")
    public Result<?> orderPage(HttpServletRequest request,OrderPageReq orderPageReq){
        orderPageReq.setToken(TokenUtils.getTokenByRequest(request));
        return orderService.orderPage3(orderPageReq);
    }

    @ApiOperation(value = "水洗店水洗订单分页", notes = "水洗店水洗订单分页")
    @GetMapping("/wash/shop/page")
    public Result<?> shopWashOrderPage(HttpServletRequest request,OrderPageReq orderPageReq){
        orderPageReq.setToken(TokenUtils.getTokenByRequest(request));
        return orderService.shopWashOrderPage(orderPageReq);
    }

    @ApiOperation(value = "详情", notes = "详情")
    @GetMapping("/one")
    public Result<?> orderDetail(HttpServletRequest request,String id){
        return orderService.orderDetail3(id,TokenUtils.getTokenByRequest(request));
    }

    @ApiOperation(value = "水洗店水洗订单详情", notes = "水洗店水洗订单详情")
    @GetMapping("/wash/shop/one")
    public Result<?> shopWashOrderDetail(HttpServletRequest request,String id){
        return orderService.shopWashOrderDetail(id,TokenUtils.getTokenByRequest(request));
    }

    @ApiOperation(value = "退货、换货申请")
    @PostMapping("/refund")
    public Result<?> applyRefundOrder(HttpServletRequest request,ApplyRefundOrderReq applyRefundOrderReq){
        applyRefundOrderReq.setToken(TokenUtils.getTokenByRequest(request));
        return orderService.applyRefundOrder(applyRefundOrderReq);
    }


    @ApiOperation(value = "下订单")
    @PostMapping("/create")
    public Result<?> createOrder(HttpServletRequest request, @RequestParam String req){
        return orderService.createOrder4(req,TokenUtils.getTokenByRequest(request));
    }

    @ApiOperation(value = "订单支付")
    @PostMapping("/pay")
    public Result<?> orderPay(HttpServletRequest request,OrderPayReq orderPayReq){
        orderPayReq.setToken(TokenUtils.getTokenByRequest(request));
        return orderService.orderPay2(orderPayReq);
    }


    @PostMapping("/notify")
    public Object orderNotify(@RequestBody String requestBody){
        return orderService.orderNotify5(requestBody);
    }


    @ApiOperation(value = "确认收货")
    @PostMapping("/confirm")
    public Result<?> confirmOrder(HttpServletRequest request,ConfirmOrderReq confirmOrderReq){
        confirmOrderReq.setToken(TokenUtils.getTokenByRequest(request));
        return orderService.confirmOrder3(confirmOrderReq);
    }

    @ApiOperation(value = "上传自己的桌布")
    @PostMapping("/upload/tablecloth")
    public Result<?> uploadTablecloth(HttpServletRequest request,UploadTableclothReq uploadTableclothReq){
        uploadTableclothReq.setToken(TokenUtils.getTokenByRequest(request));
        return orderService.uploadTablecloth(uploadTableclothReq);
    }

    @ApiOperation(value = "确认接单")
    @PostMapping("/confirm/accept")
    public Result<?> confirmAcceptOrder(HttpServletRequest request,ConfirmAcceptOrderReq confirmAcceptOrderReq){
        confirmAcceptOrderReq.setToken(TokenUtils.getTokenByRequest(request));
        return orderService.confirmAcceptOrder(confirmAcceptOrderReq);
    }


    @ApiOperation(value = "换货支付")
    @PostMapping("/replace/pay")
    public Result<?> replaceOrderPay(HttpServletRequest request,ReplaceOrderPayReq replaceOrderPayReq){
        replaceOrderPayReq.setToken(TokenUtils.getTokenByRequest(request));
        return orderService.replaceOrderPay(replaceOrderPayReq);
    }


    @PostMapping("/replace/notify")
    public Object replaceOrderNotify(@RequestBody String requestBody){
        return orderService.replaceOrderNotify(requestBody);
    }


    @ApiOperation(value = "换货发货")
    @PostMapping("/send/logistics")
    public Result<?> sendLogistics(HttpServletRequest request,SendLogisticsReq sendLogisticsReq){
        sendLogisticsReq.setToken(TokenUtils.getTokenByRequest(request));
        return orderService.sendLogistics(sendLogisticsReq);
    }

    @ApiOperation(value = "订单详情列表")
    @GetMapping("/detail/list")
    public Result<?> getOrderDetails(String id){
        return orderService.getOrderDetails(id);
    }

    @ApiOperation(value = "取消订单")
    @PostMapping("/cancel")
    public Result<?> cancelOrder(HttpServletRequest request,CancelOrderReq cancelOrderReq){
        cancelOrderReq.setToken(TokenUtils.getTokenByRequest(request));
        return orderService.cancelOrder2(cancelOrderReq);
    }

    @ApiOperation(value = "水洗店水洗订单确认收货")
    @PostMapping("/shop/wash/receipt")
    public Result<?> shopReceiptOrder(HttpServletRequest request,ShopReceiptOrderReq shopReceiptOrderReq){
        shopReceiptOrderReq.setToken(TokenUtils.getTokenByRequest(request));
        return orderService.shopReceiptOrder(shopReceiptOrderReq);
    }

    @ApiOperation(value = "酒店端水洗订单确认收货")
    @PostMapping("/wash/receipt")
    public Result<?> receiptWashOrder(HttpServletRequest request,ShopReceiptOrderReq shopReceiptOrderReq){
        shopReceiptOrderReq.setToken(TokenUtils.getTokenByRequest(request));
        return orderService.receiptWashOrder(shopReceiptOrderReq);
    }


    @ApiOperation(value = "修改上传物品得数量")
    @PostMapping("/edit/lease/num")
    public Result<?> editLeaseNum(HttpServletRequest request,EditLeaseNumReq editLeaseNumReq){
        editLeaseNumReq.setToken(TokenUtils.getTokenByRequest(request));
        return orderService.editLeaseNum(editLeaseNumReq);

    }

}
