package shop.alien.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.vo.LifeUserOrderVo;
import shop.alien.store.service.LifeUserOrderService;

@Api(tags = {"二期平台-订单管理"})
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/platformLifeUserOrder")
@RequiredArgsConstructor
public class PlatformOrderController {

    private final LifeUserOrderService lifeUserOrderService;



    @ApiOperation("查询订单列表")
    @ApiOperationSupport(order = 5)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", required = true),
            @ApiImplicitParam(name = "size", value = "每页数量", required = true),
            @ApiImplicitParam(name = "orderStatus", value = "订单状态,-1，全部（可以不传）；0，待支付;1，已支付/待使用;2，已核销；3，已过期;4，已取消;5.已退款，全退款了才算", required = false),
            @ApiImplicitParam(name = "orderNo", value = "订单号", required = false),
            @ApiImplicitParam(name = "couponName", value = "优惠券名称", required = false),
            @ApiImplicitParam(name = "couponType", value = "优惠券类型", required = false),
            @ApiImplicitParam(name = "storeName", value = "门店名称", required = false),
            @ApiImplicitParam(name = "buyStartTime", value = "购买时间开始", required = false),
            @ApiImplicitParam(name = "buyEndTime", value = "购买时间结束", required = false),
            @ApiImplicitParam(name = "payStartTime", value = "支付时间开始", required = false),
            @ApiImplicitParam(name = "payEndTime", value = "支付时间结束", required = false),
            @ApiImplicitParam(name = "finishStartTime", value = "核销时间开始", required = false),
            @ApiImplicitParam(name = "finishEndTime", value = "核销时间结束", required = false),
    })
    @GetMapping("/queryOrderList")
    public R<IPage<LifeUserOrderVo>> queryOrderList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                        @RequestParam(value = "size", defaultValue = "10") Integer size,
                                                        @RequestParam(value = "orderNo", required = false) String orderNo,
                                                        @RequestParam(required = false, defaultValue = "-1") String orderStatus,
                                                        @RequestParam(required = false) String couponName,
                                                        @RequestParam(required = false) String couponType,
                                                        @RequestParam(required = false) String storeName,
                                                        @RequestParam(value = "buyStartTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd 00:00:00")String buyStartTime,
                                                        @RequestParam(value = "buyEndTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd 23:59:59") String buyEndTime,
                                                        @RequestParam(value = "payStartTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd 00:00:00")String payStartTime,
                                                        @RequestParam(value = "payEndTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd 23:59:59") String payEndTime,
                                                        @RequestParam(value = "finishStartTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd 00:00:00")String finishStartTime,
                                                        @RequestParam(value = "finishEndTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd 23:59:59") String finishEndTime
                                                        ) {
            log.info("查询订单列表,page={},size={},orderNo={},orderStatus={},couponName={},couponType={},storeName={},buyStartTime={},buyEndTime={},payStartTime={},payEndTime={},finishStartTime={},finishEndTime={}",
                    page, size, orderNo, orderStatus, couponName, couponType, storeName, buyStartTime, buyEndTime, payStartTime, payEndTime, finishStartTime, finishEndTime);
        return R.data(lifeUserOrderService.queryOrderList(page, size, orderNo, orderStatus, couponName, couponType, storeName, buyStartTime, buyEndTime, payStartTime, payEndTime, finishStartTime, finishEndTime));
    }

    @ApiOperation("查询订单详情")
    @ApiOperationSupport(order = 6)
    @GetMapping("/queryOrderDetail")
    public R queryOrderDetail(@RequestParam String orderId) {
        log.info("userOrder.queryOrderDetail:{}", orderId);
        return lifeUserOrderService.queryOrderDetail(orderId);
    }

    @ApiOperation("中台查询订单列表")
    @ApiOperationSupport(order = 5)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", required = true),
            @ApiImplicitParam(name = "size", value = "每页数量", required = true),
            @ApiImplicitParam(name = "orderStatus", value = "订单状态,-1，全部（可以不传）；0，待支付;1，已支付/待使用;2，已核销；3，已过期;4，已取消;5.已退款，全退款了才算", required = false),
            @ApiImplicitParam(name = "orderNo", value = "订单号", required = false),
            @ApiImplicitParam(name = "couponName", value = "优惠券名称", required = false),
            @ApiImplicitParam(name = "couponType", value = "优惠券类型", required = false),
            @ApiImplicitParam(name = "storeName", value = "门店名称", required = false),
            @ApiImplicitParam(name = "buyStartTime", value = "购买时间开始", required = false),
            @ApiImplicitParam(name = "buyEndTime", value = "购买时间结束", required = false),
            @ApiImplicitParam(name = "payStartTime", value = "支付时间开始", required = false),
            @ApiImplicitParam(name = "payEndTime", value = "支付时间结束", required = false),
            @ApiImplicitParam(name = "finishStartTime", value = "核销时间开始", required = false),
            @ApiImplicitParam(name = "finishEndTime", value = "核销时间结束", required = false),
    })
    @GetMapping("/queryPlatformOrderList")
    public R<IPage<LifeUserOrderVo>> queryPlatformOrderList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                    @RequestParam(value = "size", defaultValue = "10") Integer size,
                                                    @RequestParam(value = "orderNo", required = false) String orderNo,
                                                    @RequestParam(required = false, defaultValue = "-1") String orderStatus,
                                                    @RequestParam(required = false) String couponName,
                                                    @RequestParam(required = false) String couponType,
                                                    @RequestParam(required = false) String storeName,
                                                    @RequestParam(value = "buyStartTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd 00:00:00")String buyStartTime,
                                                    @RequestParam(value = "buyEndTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd 23:59:59") String buyEndTime,
                                                    @RequestParam(value = "payStartTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd 00:00:00")String payStartTime,
                                                    @RequestParam(value = "payEndTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd 23:59:59") String payEndTime,
                                                    @RequestParam(value = "finishStartTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd 00:00:00")String finishStartTime,
                                                    @RequestParam(value = "finishEndTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd 23:59:59") String finishEndTime
    ) {
        log.info("查询订单列表,page={},size={},orderNo={},orderStatus={},couponName={},couponType={},storeName={},buyStartTime={},buyEndTime={},payStartTime={},payEndTime={},finishStartTime={},finishEndTime={}",
                page, size, orderNo, orderStatus, couponName, couponType, storeName, buyStartTime, buyEndTime, payStartTime, payEndTime, finishStartTime, finishEndTime);
        return R.data(lifeUserOrderService.queryPlatformOrderList(page, size, orderNo, orderStatus, couponName, couponType, storeName, buyStartTime, buyEndTime, payStartTime, payEndTime, finishStartTime, finishEndTime));
    }

}
