package com.iformall.service;

import com.github.pagehelper.PageInfo;
import com.iformall.common.ResultData;
import com.iformall.domain.dto.OrderSaveDto;
import com.iformall.domain.po.*;
import com.iformall.domain.vo.WxCouponSendVo;
import com.iformall.domain.vo.WxOrderCouponPressVo;
import com.iformall.domain.vo.WxOrderCouponVo;
import com.iformall.domain.vo.WxOrderQueryVo;
import com.iformall.enums.EnumOrderStatus;

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

public interface WxOrderService {

	/**
     * 根据实体查询分页列表
     *
     * @param record
     * @param pageIndex
     * @param pageSize
     * @return
     */
	PageInfo<WxOrder> listAsPage(WxOrder record, Integer pageIndex, Integer pageSize);


    /**
     * 根据日期 b用户查刷卡支付list
     *
     * @param bUserId B端用户)
     */

    ResultData microPayListOnDateAsPage(Long bUserId, Integer type, String date, Integer pageIndex, Integer pageSize);

    /**
     * 付款码支付
     * @param user
     * @param totalFeeStr
     * @return 订单id
     */
    WxOrder saveMicroPayOrder(WxMerchantBUser user, String totalFeeStr);

    /**
     * 付款码支付v2
     * @param user
     * @param cUser
     * @param payment
     * @return 订单id
     */
    WxOrder saveMicroPayOrderV2(WxMerchantBUser user, WxCUser cUser, Integer payment);

    /**
     * 商户码-储值卡支付
     * @param merchant
     * @param cUserId
     * @param totalFeeStr
     * @param payment
     * @return 订单id
     */
    WxOrder saveCardPayOrder(WxMerchant merchant, Long cUserId, String totalFeeStr, Integer payment);

    /**
     * 免费券订单接口
     * @param userId
     * @param couponId
     * @param wxCouponSendVo 商户注券时必须指定
     * @return WxCouponOrder
     */
    WxCouponOrder sendFreeCouponToUser(Long userId, Long couponId, WxCouponSendVo wxCouponSendVo);

    /**
     * orderSuccess 订单已支付
     * @param updateOrder
     * @return
     */
    int couponOrderSuccess(WxOrder updateOrder);

    /**
     * microPayOrderSuccess 刷卡支付成功
     * @param updateOrder
     * @return
     */
    int microPayOrderSuccess(WxOrder updateOrder);

    /**
     * updateOrderStatus 更新订单状态, 只针对已取消及已退款
     * @param updateOrder
     * @param enumOrderStatus
     */
    int updateOrderStatus(WxOrder updateOrder, EnumOrderStatus enumOrderStatus);

    /**
     * 订单关单
     */
    ResultData orderClose(WxOrder order);

    /**
     * 根据Id获得实体
     *
     * @param id
     * @return
     */
    WxOrder getById(Long id);
    
        /**
     * 保存或更新实体
     *
     * @param record
     */
    void saveOrUpdate(WxOrder record);

    /**
     * 根据Id删除实体
     *
     * @param id
     */
    void deleteById(Long id);
    /**
     * 条件查询不分页
     * @param record
     * @return
     */
    List<WxOrder> findList(WxOrder record);



    PageInfo<WxOrderCouponVo> listCUserVoAsPage(WxOrder record, Integer pageIndex, Integer pageSize);


    WxOrderCouponVo detailCUserVo(WxOrder record);

    void stockBack(WxOrder updateOrder);

    /**
     * microPay分账
     * @param orderId
     * @param payOrderId
     */
    void shareForMicroPay(String tenantId, Long orderId, Long payOrderId);

    PageInfo<WxOrder> listOrderAsPage(WxOrderQueryVo wxOrder, Integer pageNum, Integer pageSize);

    Map<String,Object> queryOrderSummary(String tenantId);

    /**
     * 砍价订单
     */
    PageInfo<WxOrderCouponPressVo> listPressVoAsPage(WxOrder record, Integer pageIndex, Integer pageSize);

    WxOrderCouponPressVo detailPressVo(WxOrder record);

    void updateStatusByPressCouponId(Long couponId,String tenantId,int orderStatus);

    void updateOrderStatus(WxOrder order);

    void updateOrderGroupStatusByCouponId(Long id, String tenantId, Integer code);

    void updateOrderGroupStatusByCouponChannelId(Long id, String tenantId, Integer code);


    /**
     * 下订单
     * @param user
     * @param coupon
     * @return
     */
    WxOrder saveOrderForCoupon(WxCUser user, WxCoupon coupon, OrderSaveDto orderSaveDto, boolean isPress);
    void sendOrderSuccessActionMsg(WxOrder updateOrder);

    /**
     * 未支付订单
     * @param cUser
     * @param coupon
     * @return
     */
    WxOrder getUnPaidOrder(WxCUser cUser, WxCoupon coupon);

    int countCouponConditionType1(WxCUser user);
    /**
     * 订单处理
     * 1. 检查coupon是否免费
     */
    boolean checkCouponIsFree(WxCoupon coupon);

    // 2. 创建免费订单, 领取 couponOrder
    WxOrder saveFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId, Long couponPasswordId);

    // 3. 创建有价订单
    WxOrder saveNoFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, boolean isPress, Long orderGroupId, String formId);

    /**
     * 下订单成功后处理
     * @param updateOrder
     * @param coupon
     * @param user
     */
    void actionAfterCouponOrderSuccess(WxOrder updateOrder, WxCoupon coupon, WxCUser user);

    Map<String, Long> summary(WxOrderQueryVo wxOrderQueryVo);

    void exportData(WxOrderQueryVo wxOrderQueryVo, HttpServletRequest request, HttpServletResponse response);

}
