package com.red.circle.order.app.command.pay.app.strategy.notice;

import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.component.pay.apple.ServerToServerNoticeBody;
import com.red.circle.component.pay.apple.ServerToServerNoticeCmd;
import com.red.circle.order.app.command.pay.app.receipt.ApplePurchaseService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 表示已过期订阅的自动续订成功，但该订阅在过去无法续订。检查到期日期以确定下一个续订日期和时间。
 *
 * @author pengliang on 2020/7/22
 * @deprecated
 */
@Component("RENEWAL")
@RequiredArgsConstructor
public class RenewalStrategy implements AppleServerToServerStrategy {

  private final ApplePurchaseService applePurchaseService;

  /**
   * 验证是否续订成功，创建订单
   */
  @Override
  public void doOperation(ServerToServerNoticeCmd cmd) {
    ServerToServerNoticeBody body = cmd.getBody();
    applePurchaseService
        .checkAutomaticRenewalSubscription(SysOriginPlatformEnum.valueOf(cmd.getSysOrigin()),
            cmd.getVerifyReceiptBody()
            , body.getAutoRenewProductId());
  }
}
