package com.kxs.product.biz.controller.kxsapp;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kxs.common.core.util.R;
import com.kxs.common.security.annotation.Inner;
import com.kxs.product.api.dto.kxsapp.shop.PayOrderDTO;
import com.kxs.product.api.model.KxsShopOrder;
import com.kxs.product.api.dto.kxsapp.shop.GoodsSubmitDTO;
import com.kxs.product.api.vo.kxsapp.shop.ShopGoodsListVO;
import com.kxs.product.api.vo.kxsapp.shop.ShopOrderListVO;
import com.kxs.product.biz.service.KxsShopCateService;
import com.kxs.product.biz.service.KxsShopGoodsService;
import com.kxs.product.biz.service.KxsShopOrderService;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

/**
 * 商城(Shop)控制层
 *
 * @author 系统
 * @since 2023-12-20 10:09:39
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("shop")
public class ShopController {

    /**
     * 服务对象
     */
    private final KxsShopCateService kxsShopCateService;
    private final KxsShopGoodsService kxsShopGoodsService;
    private final KxsShopOrderService kxsShopOrderService;



    /**
     * 分类列表
     *
     * @return 分类列表
     */
    @GetMapping("/categories")
    public R categories() {
        return R.ok(kxsShopCateService.getByList());
    }


    /**
     * 商品列表
     *
     * @param page 分页对象
     * @param colId 分类ID
     * @return 商品列表
     */
    @GetMapping("/goodsList")
    public R goodsList(@ParameterObject Page<ShopGoodsListVO> page, @RequestParam("colId") Integer colId) {

        return R.ok(kxsShopGoodsService.getByPage(page, colId));
    }


    /**
     * 商品详情
     *
     * @param id 主键ID
     * @return 商品详情
     */
    @GetMapping("/goodsDetail")
    public R goodsDetail(@RequestParam("id") Integer id) {
        return R.ok(kxsShopGoodsService.getByGoodsDetail(id));
    }


    /**
     * 提交订单
     *
     * @param param 实体对象
     * @return 提交订单
     */
    @PostMapping("/goodsSubmit")
    public R goodsSubmit(@RequestBody GoodsSubmitDTO param) {
        return kxsShopOrderService.submitOrder(param);
    }


    /**
     * 待付款待发货数量
     *
     * @return 订单详情
     */
    @GetMapping("/orderUnCount")
    public R orderUnCount() {
        return R.ok(kxsShopOrderService.orderUnCount());
    }

    /**
     * 查询指定时间区间的电签大机券订单
     *
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return 订单详情
     */
    @Inner
    @GetMapping("/getDateBetweenOrders")
    public R getDateBetweenOrders(@RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {

        return R.ok(kxsShopOrderService.getDateBetweenOrders(startTime, endTime));
    }

    /**
     * 订单列表
     *
     * @param param 状态
     * @param page   分页对象
     * @return 订单详情
     */
    @GetMapping("/orderList")
    public R orderList(@ParameterObject Page<ShopOrderListVO> page, @ParameterObject KxsShopOrder param) {

        return R.ok(kxsShopOrderService.getByPage(page, param));
    }

    /**
     * 订单详情
     *
     * @param id 订单ID
     * @return 订单详情
     */
    @GetMapping("/orderDetail")
    public R orderDetail(@RequestParam("id") Integer id) {
        return R.ok(kxsShopOrderService.getByOrderId(id));
    }


    /**
     * 发起支付
     *
     * @param param 订单实体
     * @return 发起支付
     */
    @PostMapping("/orderPay")
    public R orderPay(@RequestBody PayOrderDTO param) {

        return kxsShopOrderService.payOrder(param);
    }


    /**
     * 取消订单
     *
     * @param param 实体对象
     * @return 取消订单
     */
    @PutMapping("/orderCancel")
    public R orderCancel(@RequestBody KxsShopOrder param) {

        return kxsShopOrderService.cancelOrder(param);
    }


    /**
     * 确认收货
     *
     * @param param 实体对象
     * @return 确认收货
     */
    @PutMapping("/orderConfirm")
    public R orderConfirm(@RequestBody KxsShopOrder param) {

        return R.ok(kxsShopOrderService.confirmOrder(param));
    }

    /**
     * 订单过期
     */
    @Inner
    @GetMapping("/shopOrderTimeout")
    public void shopOrderTimeout() {

        kxsShopOrderService.shopOrderTimeout();
    }





}

