import UIKit
import AdViewSDK

fileprivate let storedImpVideoInterstitial = "POSIDxdsaplpm4ar1"

class InAppVideoInterstitialViewController: InterstitialBaseViewController, InterstitialAdUnitDelegate {

    // adview
    private var renderingInterstitial: InterstitialRenderingAdUnit!
    
    override func loadView() {
        super.loadView()
        
        createAd()
    }

    func createAd() {
        // 1. Create a InterstitialRenderingAdUnit
        renderingInterstitial = InterstitialRenderingAdUnit(configID: storedImpVideoInterstitial)
        
        // 2. Configure the InterstitialRenderingAdUnit
        renderingInterstitial.adFormats = [.video]
        renderingInterstitial.delegate = self
        
        // 3. Load the interstitial ad
        renderingInterstitial.loadAd()
    }
    
    // MARK: - InterstitialAdUnitDelegate

    func interstitialDidReceiveAd(_ interstitial: InterstitialRenderingAdUnit) {
        interstitial.show(from: self)
    }
    
    func interstitial(_ interstitial: InterstitialRenderingAdUnit, didFailToReceiveAdWithError error: Error?) {
        AdViewDemoLogger.shared.error("Interstitial Rendering ad unit did fail to receive ad with error: \(error)")
    }
}
