package com.sqx.modules.order.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.order.controller.query.GoodsSkuQuery;
import com.sqx.modules.order.dto.OrderFinishByShopDTO;
import com.sqx.modules.order.dto.OrderQueryDto;
import com.sqx.modules.order.entity.Evaluate;
import com.sqx.modules.order.entity.OrderGoods;
import com.sqx.modules.order.entity.TbOrder;
import com.sqx.modules.pay.dto.PayOrderDTO;
import com.sqx.modules.pay.vo.PayTransactionsVO;
import com.sqx.modules.utils.excel.ExcelData;

import java.time.LocalDateTime;
import java.util.List;

public interface AppOrderService extends IService<TbOrder> {

    int updateOrderPrint(Long OrderId);

    void insertOrder(Long userId, Long shopId, Long goodsId, Integer num, Long skuId, String skuMessage, Integer orderType);

    Result print(Long orderId, Integer isAppend);

    Result updateOrder(TbOrder order);

    Result deleteOrderList(List<Integer> orderId);

    Result selectOrderList(Long userId, Long shopId, Integer status, Integer orderType, Integer page, Integer limit);

    TbOrder selectOrderByNum(String orderNum);

    Result selectAllOrder(Integer page, Integer limit, Integer status, String phone, Long shopId, String userName, String orderNumber, Integer orderType,String shopName, String transactionId);

    Result selectAllOrderAdmin(OrderQueryDto queryDto);

    ExcelData excelAllOrderAdmin(OrderQueryDto queryDto);

    Result selectOrderByUserId(Long userId, String date, String dateType);

    Result selectOrderDetails(Integer page, Integer limit, Long userId);

    Result waitTakeFood(Long userId, Integer orderType, Integer page, Integer limit, Integer status);

    List<TbOrder> selectOrderByParentId(Long parentId);

    Result selectOrderById(Long orderId);

    Result updateGoodsNum(Long orderGoodsId, Integer type, Integer num, Long shopId);

    TbOrder selectOrderByIds(Long orderId);

    Result emptyShoppingTrolley(Long userId, Long shopId);

    Result employCoupon(Long userId, Long parentId, Long couponId);

    Result deleteCouponByOrderId(Long orderId);

    Result buyGoods(Long userId, Long shopId, Long goodsId, Integer num, Long skuId, String skuMessage, Integer orderType);

    Result echoOrder(Long userId, Long shopId, Long goodsId);

    Result selectBuyGoods(Long userId, Long orderId);

    Result adminCancelOrder(Long orderId);

    Result accomplishOrder(Long orderId, Integer type);

    Result insertEvaluate(Evaluate evaluate);

    Result selectShoppingTrolley(Long userId);

    Result selectShoppingTrolleyByShopId(Long userId, Long shopId);

    Result userCancelOrder(Long orderId);

    Result shopReplyEvaluate(String orderNumber, String shopReplyMessage);

    Result joinOrder(Long userId, Long orderId, Long shopId, Long goodsId, Integer num, Long skuId, String skuMessage);

    Result shareTheBill(Long userId, Long shopId);

    Result selectShareTheBill(Long userId, Long orderId);

    Result deleteByGoods(Long userId, Long id);

    Result deleteShareTheBill(Long userId, Long orderId);

    Result deleteOrder(Long userId, Long orderId);

    IPage<Evaluate> getEvaluateList(Evaluate evaluate, Integer page, Integer limit);

    Result deleteEvaluateById(Long userId, Long id);

    /**
     * 准备订单，用于订单支付前检验订单信息、填充订单必要参数
     * @param userId 用户id
     * @param payOrderDTO 支付订单dto
     * @return 订单信息
     */
    TbOrder prepareOrder(Long userId, PayOrderDTO payOrderDTO);

    /**
     * 根据订单扣减库存
     * @param order 订单信息
     */
    void subStock(TbOrder order);

    /**
     * 支付成功后更新订单
     * @param order 订单信息
     */
    void updateOrderAfterPaySuccess(TbOrder order);

    /**
     * 查询订单商品
     * @param orderId 订单id
     * @return 订单商品列表
     */
    List<OrderGoods> getOrderGoods(Long orderId);

    /**
     * 查询用户在指定店铺的有效订单数量
     *      (排除当前orderId，如果有的话)
     * @param shopId 店铺id
     * @param userId 用户id
     * @param orderId 订单id
     * @return 订单数量
     */
    int countByShopIdAndUserId(Long shopId, Long userId, Long orderId);

    /**
     * 查询用户当天在指定店铺参与某活动的有效订单数量
     *      (排除当前orderId，如果有的话)
     * @param shopId 店铺id
     * @param activityId 活动id
     * @param userId 用户id
     * @param orderId 订单id
     * @return 订单数量
     */
    int countByShopIdAndActivityIdAndUserIdAndCurDate(Long shopId, Long activityId, Long userId, Long orderId);

    /**
     * 店铺完成订单
     * @param orderFinishByShopDTO 完成订单参数
     */
    void finishOrderByShop(OrderFinishByShopDTO orderFinishByShopDTO);

    /**
     * 添加送达照片
     * @param orderId 订单id
     * @param img 图片地址
     */
    void addReceiveImg(Long orderId, String img);

    /**
     * 获取当前待接单的订单id集合
     * @return 订单id集合
     */
    List<Long> getCurWaitReceivingOrderIds();

    /**
     * 获取 datetime 前正在制作中的订单
     * @param datetime 时间
     * @return 订单列表
     */
    List<TbOrder> getProdIngOrders(LocalDateTime datetime);

    Result selectOrder(Long userId, Integer orderId,Integer page, Integer limit);

    Result updateTimeOutOrder(Long userId, Integer orderId);

    /**
     * 获取交易参数
     * @param userId 用户id
     * @param payOrderDTO 支付参数
     * @return 交易参数
     */
    PayTransactionsVO getTransactionsParam(Long userId, PayOrderDTO payOrderDTO);

    Result selectAllOrderTotalPrice(OrderQueryDto queryDto);


    List<TbOrder> changeTimeOutOrder(long time);

    /**
     * 查询商品sku销售数量
     * @param query 查询参数
     * @return 商品sku销售数量
     */
    PageUtils getGoodsSkuSalesCount(GoodsSkuQuery query);

    /**
     * 导出商品sku销售数量
     * @param query 查询参数
     */
    void exportGoodsSkuSalesCount(GoodsSkuQuery query);
}
