package com.red.circle.order.domain.gateway;


import com.google.api.services.androidpublisher.model.ProductPurchase;
import com.google.api.services.androidpublisher.model.SubscriptionPurchase;
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.component.pay.apple.LatestEffectiveBody;
import com.red.circle.component.pay.apple.PendingRenewalInfo;
import com.red.circle.order.domain.order.OrderStatusEnum;
import com.red.circle.order.domain.order.PurchaseHistory;

/**
 * @author pengliang on 2020/3/20 12:48
 */
public interface InAppPurchaseGateway {

  /**
   * 是否包含订单id
   *
   * @param orderId 订单id
   * @return true/false
   */
  boolean existOrder(String orderId);

  /**
   * 获取订单信息
   *
   * @param orderId 订单id
   * @return 订单信息
   */
  PurchaseHistory getOrder(String orderId);

  /**
   * 获取指定订单信息.
   */
  PurchaseHistory getById(String id);

  /**
   * 添加购买记录
   *
   * @param purchaseHistory 记录
   */
  void addInAppPurchase(PurchaseHistory purchaseHistory);

  /**
   * 保存 apple 购买单据
   *
   * @param userId              用户id
   * @param sysOrigin           系统来源
   * @param latestEffectiveBody 单据内容
   */
  void addAppleReceipt(Long userId, SysOriginPlatformEnum sysOrigin,
      LatestEffectiveBody latestEffectiveBody);

  /**
   * 刷新 apple 等待续费单据
   *
   * @param userId             用户id
   * @param sysOrigin          来源系统
   * @param pendingRenewalInfo 参数
   */
  void resetApplePendingRenewalInfo(Long userId, SysOriginPlatformEnum sysOrigin,
      PendingRenewalInfo pendingRenewalInfo);

  /**
   * 保存google 商品单据
   *
   * @param sysOrigin       来源系统
   * @param userId          用户id
   * @param productPurchase 购买单据
   */
  void addGoogleLatestPurchase(SysOriginPlatformEnum sysOrigin, Long userId,
      ProductPurchase productPurchase);

  /**
   * 保存google 订阅商品单据
   *
   * @param sysOrigin            来源系统
   * @param userId               用户id
   * @param subscriptionPurchase 购买单据
   */
  void addGoogleLatestSubscription(SysOriginPlatformEnum sysOrigin, Long userId,
      SubscriptionPurchase subscriptionPurchase);

  /**
   * 获取用户id
   *
   * @param originOrderId 初始订单id
   * @return 用户id
   */
  Long getUserIdByOriginOrderId(String originOrderId);

  /**
   * 获取用户id
   *
   * @param orderId 初始订单id
   * @return 用户id
   */
  Long getUserIdByOrderId(String orderId);

  /**
   * 更改用户状态
   *
   * @param orderStatusEnum 用户状态
   * @param id              购买记录id
   */
  void updateStatus(OrderStatusEnum orderStatusEnum, Long id);
}
