package co.yixiang.yshop.module.order.service.storeorder;

import co.yixiang.yshop.framework.security.core.LoginUser;
import co.yixiang.yshop.module.order.controller.app.afterorder.param.AppOrderRefundParam;
import co.yixiang.yshop.module.order.controller.app.order.param.AppComputeOrderParam;
import co.yixiang.yshop.module.order.controller.app.order.param.AppConfirmOrderParam;
import co.yixiang.yshop.module.order.controller.app.order.param.AppOrderParam;
import co.yixiang.yshop.module.order.controller.app.order.param.AppPayParam;
import co.yixiang.yshop.module.order.controller.app.order.vo.AppConfirmOrderVo;
import co.yixiang.yshop.module.order.controller.app.order.vo.AppStoreOrderQueryVo;
import co.yixiang.yshop.module.order.dal.dataobject.storeorder.StoreOrderDO;
import co.yixiang.yshop.module.shop.controller.app.vo.WriteOffDTO;
import com.baomidou.mybatisplus.extension.service.IService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 订单 Service 接口
 *
 * @author yshop
 */
public interface AppStoreOrderService extends IService<StoreOrderDO> {
    /**
     * 返回订单确认数据
     *
     * @param uid   用户ID
     * @param param
     * @return ConfirmOrderVO
     */
    AppConfirmOrderVo confirmOrder(Long uid, AppConfirmOrderParam param);


    /**
     * 订单信息
     *
     * @param unique 唯一值或者单号
     * @param uid    用户id
     * @return YxStoreOrderQueryVo
     */
    AppStoreOrderQueryVo getOrderInfo(String unique, Long uid);

    /**
     * 计算订单价格
     *
     * @param uid   用户uid
     * @param key   订单缓存key
     * @param param 计算订单参数
     * @return map
     */
    Map<String, Object> computedOrder(Long uid, String key, AppComputeOrderParam param);

    /**
     * 创建订单
     *
     * @param uid   用户uid
     * @param key   key
     * @param param param
     * @return map
     */
    Map<String, Object> createOrder(Long uid, String key, AppOrderParam param);


    /**
     * 第三方支付查单
     *
     * @param param 订单
     * @param uid   用户id
     */
    Boolean orderQuery(Long uid, AppPayParam param) throws Exception;


    /**
     * 第三方支付
     *
     * @param param 订单
     * @param uid   用户id
     */
    Map<String, String> pay(Long uid, AppPayParam param) throws Exception;

    /**
     * 微信支付回调
     */
    void wxPayNotify(HttpServletRequest request, HttpServletResponse response) throws Exception;


    void wxPayNotify(String orderId, Map<String, String> resultMap) throws Exception;

    /**
     * 余额支付
     *
     * @param orderId 订单号
     * @param uid     用户id
     */
    void yuePay(String orderId, Long uid);

    /**
     * 支付成功后操作
     *
     * @param orderId 订单号
     * @param payType 支付方式
     */
    void paySuccess(String orderId, String payType);


    /**
     * 订单列表
     *
     * @param uid   用户id
     * @param type  OrderStatusEnum
     * @param page  page
     * @param limit limit
     * @return list
     */
    List<AppStoreOrderQueryVo> orderList(Long uid, int type, int page, int limit);

    /**
     * 处理订单返回的状态
     *
     * @param order order
     * @return YxStoreOrderQueryVo
     */
    AppStoreOrderQueryVo handleOrder(AppStoreOrderQueryVo order);

    /**
     * 订单确认收货
     *
     * @param orderId 单号
     * @param uid     uid
     */
    void takeOrder(String orderId, Long uid);

    /**
     * 订单评价
     *
     * @param uid          用户ID
     * @param unique       订单orderCart唯一值
     * @param comment      评论内容
     * @param pics         图片
     * @param productScore 评分
     * @param serviceScore 评分
     */
    void orderComment(Long uid, String unique, String comment, String pics, String productScore,
                      String serviceScore);

    /**
     * 删除订单
     *
     * @param orderId 单号
     * @param uid     uid
     */
    void removeOrder(String orderId, Long uid);

    /**
     * 未付款取消订单
     *
     * @param orderId 订单号
     * @param uid     用户id
     */
    void cancelOrder(String orderId, Long uid);

    /**
     * 确认订单退款
     *
     * @param param 退款参数
     */
    void orderRefund(AppOrderRefundParam param) throws Exception;

    /**
     * 批量退款
     *
     * @param ids  退款id集合
     * @param type 退款商品类型
     */
    void batchRefund(List<Long> ids, Integer type) throws Exception;


    /**
     * 核销订单
     *
     * @param user 用户信息
     * @param dto  核销信息
     */
    void writeOff(LoginUser user, WriteOffDTO dto);

    /**
     * 查询订单详情
     *
     * @param key /
     * @param uid /
     * @return /
     */
    AppStoreOrderQueryVo orderDetail(String key, Long uid);

    void updatePayInfo(AppStoreOrderQueryVo orderInfo, Map<String, String> packageParams);

    void updatePayInfo(AppStoreOrderQueryVo orderInfo, String outTradeNo, String transactionId);

    /**
     * 拼团结束
     *
     * @param teamworkId
     * @return
     */
    void teamworkEnd(Long teamworkId) throws Exception;

    /**
     * 订单退款 已支付未发货的订单退款,回退积分,回退优惠券,回退库存
     *
     * @param id  订单id
     * @param uid 用户id
     */
    void refundOrder(String id, Long uid);
}
