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/24
 */
@Slf4j
@Component("INTERACTIVE_RENEWAL")
@RequiredArgsConstructor
public class InteractiveRenewalStrategy 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());
  }
}
