#import "InAppDisplayRewardedViewController.h"
#import "AdViewDemoMacros.h"

NSString * const storedImpBannerRewardedInApp = @"POSIDxdsaplpm4ar1";

@interface InAppDisplayRewardedViewController ()

// adview
@property (nonatomic) ADVIEW_RewardedAdUnit * rewardedAdUnit;

@end

@implementation InAppDisplayRewardedViewController

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

- (void)createAd {
    // 1. Create a ADVIEW_RewardedAdUnit
    self.rewardedAdUnit = [[ADVIEW_RewardedAdUnit alloc] initWithConfigID:storedImpBannerRewardedInApp];
    self.rewardedAdUnit.delegate = self;
    
    // 2. Load the rewarded ad
    [self.rewardedAdUnit loadAd];
}

// MARK: - ADVIEW_RewardedAdUnitDelegate

- (void)rewardedAdDidReceiveAd:(ADVIEW_RewardedAdUnit *)rewardedAd {
    if (rewardedAd.isReady) {
        [rewardedAd showFrom:self];
    }
}

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

- (void)rewardedAdUserDidEarnReward:(ADVIEW_RewardedAdUnit *)rewardedAd reward:(ADVIEW_Reward *)reward {
    NSLog(@"User did earn reward - type: %@, count: %f", reward.type, [reward.count doubleValue]);
}

@end
