#import "InAppVideoInterstitialViewController.h"
#import "AdViewDemoMacros.h"

NSString * const storedImpVideoInterstitialInApp = @"POSIDxdsaplpm4ar1";

@interface InAppVideoInterstitialViewController ()

// adview
@property (nonatomic) ADVIEW_InterstitialRenderingAdUnit * renderingInterstitial;

@end

@implementation InAppVideoInterstitialViewController

- (void)loadView {
    [super loadView];
    
    [self createAd];
}

- (void)createAd {
    // 1. Create a ADVIEW_InterstitialRenderingAdUnit
    self.renderingInterstitial = [[ADVIEW_InterstitialRenderingAdUnit alloc] initWithConfigID:storedImpVideoInterstitialInApp];
    
    // 2. Configure the ADVIEW_InterstitialRenderingAdUnit
    self.renderingInterstitial.adFormats = [[NSSet alloc] initWithObjects:ADVIEW_AdFormat.video, nil];
    self.renderingInterstitial.delegate = self;
    
    // 3. Load the interstitial ad
    [self.renderingInterstitial loadAd];
}

// MARK: - ADVIEW_InterstitialAdUnitDelegate

- (void)interstitialDidReceiveAd:(ADVIEW_InterstitialRenderingAdUnit *)interstitial {
    [self.renderingInterstitial showFrom:self];
}

- (void)interstitial:(ADVIEW_InterstitialRenderingAdUnit *)interstitial didFailToReceiveAdWithError:(NSError *)error {
    AdViewDemoLogError(@"%@", error.localizedDescription);
}

@end
