package com.red.circle.order.app.command.pay.app.model;

import com.red.circle.framework.dto.ClientObject;
import java.util.Objects;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author pengliang on 2020/11/23
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class AutoSubscription extends ClientObject {

  /**
   * 订阅事件
   */
  private SubscriptionEvent subscriptionEvent;

  /**
   * subscriptionEvent = AUTO
   */
  private ExtractInAppPurchaseReceipt extractInAppPurchaseReceipt;

  private AutoSubscription() {
  }

  public static AutoSubscription createNone() {
    AutoSubscription googleAutoSubscription = new AutoSubscription();
    googleAutoSubscription.setSubscriptionEvent(SubscriptionEvent.NONE);
    return googleAutoSubscription;
  }

  public static AutoSubscription createRefund() {
    AutoSubscription googleAutoSubscription = new AutoSubscription();
    googleAutoSubscription.setSubscriptionEvent(SubscriptionEvent.REFUND);
    return googleAutoSubscription;
  }

  public static AutoSubscription createAutoRenew(
      ExtractInAppPurchaseReceipt extractInAppPurchaseReceipt) {
    AutoSubscription googleAutoSubscription = new AutoSubscription();
    googleAutoSubscription.setSubscriptionEvent(SubscriptionEvent.AUTO_RENEW);
    googleAutoSubscription.setExtractInAppPurchaseReceipt(extractInAppPurchaseReceipt);
    return googleAutoSubscription;
  }

  public ProductConfigPackageGet toProductConfigPackageGetCmd() {
    return extractInAppPurchaseReceipt.toProductConfigPackageGetCmd();
  }

  public boolean isAutoRenew() {
    return Objects.equals(SubscriptionEvent.AUTO_RENEW, subscriptionEvent);
  }

  public enum SubscriptionEvent {
    /**
     * 不处理
     */
    NONE,
    /**
     * 退订
     */
    REFUND,
    /**
     * 自动续费
     */
    AUTO_RENEW

  }
}
