package com.yonge.cooleshow.biz.dal.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yonge.cooleshow.biz.dal.dto.req.OrderPayReq;
import com.yonge.cooleshow.biz.dal.dto.req.OrderReq;
import com.yonge.cooleshow.biz.dal.entity.UserOrder;
import com.yonge.cooleshow.biz.dal.enums.GoodTypeEnum;
import com.yonge.cooleshow.biz.dal.enums.OrderStatusEnum;
import com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo;
import com.yonge.cooleshow.biz.dal.vo.UserOrderVo;
import com.yonge.cooleshow.biz.dal.dto.search.OrderSearch;
import com.yonge.cooleshow.biz.dal.vo.res.OrderPayRes;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.payment.base.model.callback.PaymentCallBack;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 平台订单表 服务类
 *
 * @author liweifan
 * @date 2022-03-30
 */
public interface UserOrderService extends IService<UserOrder> {

    /**
     * 查询详情 通过订单id
     *
     * @author liweifan
     * @date 2022-03-30
     */
    UserOrderVo detail(Long id);

    /**
     * 查询详情 通过订单号
     *
     * @author liweifan
     * @date 2022-03-30
     */
    UserOrderVo detail(String orderNo, Long userId);

    /**
     * 分页查询
     *
     * @author liweifan
     * @date 2022-03-30
     */
    IPage<UserOrderVo> selectPage(IPage<UserOrderVo> page, OrderSearch query);

    /***
     * 查询集合
     * @author liweifan
     * @param: query
     * @updateTime 2022/4/15 15:05
     * @return: java.util.List<com.yonge.cooleshow.biz.dal.vo.UserOrderVo>
     */
    List<UserOrderVo> selectAllList(OrderSearch query);

    /***
     * 下单接口
     * @author liweifan
     * @param: orderReq
     * @updateTime 2022/3/31 15:42
     * @return: com.yonge.cooleshow.common.entity.HttpResponseResult<com.yonge.cooleshow.biz.dal.entity.Order>
     */
    HttpResponseResult<UserOrder> executeOrder(OrderReq orderReq);

    /***
     * 订单付款
     * @author liweifan
     * @param: payReq
     * @updateTime 2022/3/31 17:23
     * @return: com.yonge.cooleshow.common.entity.HttpResponseResult
     */
    HttpResponseResult<OrderPayRes> orderPay(OrderPayReq payReq);

    /***
     * 通过业务id查询用户正在交易中的订单
     * @author liweifan
     * @param: query
     * @updateTime 2022/4/27 16:56
     * @return: com.yonge.cooleshow.common.entity.HttpResponseResult<com.yonge.cooleshow.biz.dal.vo.UserOrderVo>
     */
    HttpResponseResult<UserOrderVo> getPendingOrder(OrderSearch query);

    /***
     * 轮询用户订单
     * @author liweifan
     * @updateTime 2022/4/13 16:27
     */
    void pollingOrder();

    /***
     * app查询订单详情
     * @author liweifan
     * @param: orderNo
     * @updateTime 2022/4/24 17:49
     * @return: com.yonge.cooleshow.biz.dal.vo.UserOrderVo
     */
    UserOrderVo detailApp(UserOrder param);

    /**
     * 通过付款单号或三方交易号查询对应订单
     *
     * @param paymentNo
     * @param transNo
     * @return
     */
    UserOrderVo getUserOrderByPaymentNoOrTransNo(String paymentNo, String transNo);

    /***
     * 取消订单
     * @author liweifan
     * @param: payReq
     * @updateTime 2022/4/21 19:39
     * @return: com.yonge.cooleshow.common.entity.HttpResponseResult<java.lang.Boolean>
     */
    HttpResponseResult<Boolean> orderCancel(OrderPayReq payReq);

    /***
     * 取消订单（未判断付款单状态）
     * @author liweifan
     * @param: userOrder
     * @param: orderStatus
     * @param: reason
     * @updateTime 2022/5/7 14:46
     */
    void doOrderCancel(UserOrderVo userOrder, OrderStatusEnum orderStatus, String reason);

    /***
     * 完成所有订单
     * @author liweifan
     * @updateTime 2022/4/27 17:38
     */
    void setSuccessStatus();

    /***
     * 查询未记录第一次购买时间的订单
     * @author liweifan
     * @param: query
     * @updateTime 2022/4/28 10:17
     * @return: java.util.List<com.yonge.cooleshow.biz.dal.entity.UserOrder>
     */
    List<UserOrder> selectUnRecordTimeOrder(OrderSearch query);

    /***
     * 修改订单状态
     * @author liweifan
     * @param: orderNo
     * @param: orderStatus
     * @updateTime 2022/5/7 15:21
     * @return: java.lang.Integer
     */
    Integer updateStatusByOrderNo(String orderNo, String orderStatus);

    /***
     * 修改订单状态（测试用）
     * @author liweifan
     * @param: orderNo
     * @param: orderStatus
     * @updateTime 2022/4/29 18:41
     */
    Boolean setOrderStatus(UserOrder param);

    /**
     * 订单完成
     *
     * @param detail
     */
    void orderSuccess(UserOrderVo detail, PaymentCallBack data);


    Date getAccountPeriodTime(UserOrderDetailVo orderDetailVo);

    /**
     * 通过goodType获取分润
     *
     * @param goodType
     * @return
     */
    BigDecimal getShareFreeByGoodType(GoodTypeEnum goodType, Long bizId);

    /**
     * 通过配置名称获取分润比例
     *
     * @param configName
     * @return
     */
    BigDecimal getShareFreeByConfigName(String configName);

}