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 lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 表示已过期订阅的自动续订成功
 *
 * @author pengliang on 2020/7/22
 */
@Slf4j
@Component("DID_RECOVER")
@RequiredArgsConstructor
public class DidRecoverStrategy 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());
  }
}
