#import "InAppDisplayInterstitialViewController.h"
#import "AdViewDemoMacros.h"

NSString * const storedImpDisplayInterstitialInApp = @"POSIDzuqwln00ml38";

@interface InAppDisplayInterstitialViewController ()

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

@end

@implementation InAppDisplayInterstitialViewController

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

- (void)createAd {
    // 1. Create a ADVIEW_InterstitialRenderingAdUnit
    self.renderingInterstitial = [[ADVIEW_InterstitialRenderingAdUnit alloc] initWithConfigID:storedImpDisplayInterstitialInApp];
    
    // 2. Configure the ADVIEW_InterstitialRenderingAdUnit
    self.renderingInterstitial.adFormats = [[NSSet alloc] initWithObjects:ADVIEW_AdFormat.banner, 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
