﻿//Example code for Unity Devs

using UnityEngine.Events;
using UnityEngine; //MonoBehavior and Debug.Log
using UnityEngine.UI;
using System;
using System.Collections.Generic;


public class VrtcalExample : MonoBehaviour
{
	//Example Ad Unit IDs

	#pragma warning disable 0414
	int shouldFail = 1;

    int bannerDisplayTwitMore = 10005;
    int bannerLive = 10001;        
	int bannerVideo = 10227;

    int interstitialDisplayTwitMore = 10009;
    int interstitialVideo = 10219;
    int interstitialVideoSuppressCloseButton = 10224;	
    #pragma warning restore 0414

    public void Start()
    {
        Vrtcal.Log("Initializing SDK...");

		Vrtcal.OnSdkInitializedEvent.AddListener(OnSdkInitializedEventHandler); 
		Vrtcal.OnSdkFailedToInitializeEvent.AddListener(OnSdkFailedToInitializeEventHandler);

		Vrtcal.OnBannerLoadedEvent.AddListener(OnBannerLoadedEventHandler);
		Vrtcal.OnBannerFailedToLoadEvent.AddListener(OnBannerFailedToLoadEventHandler);
		Vrtcal.OnBannerClickedEvent.AddListener(OnBannerClickedEventHandler);
		Vrtcal.OnBannerWillPresentModalEvent.AddListener(OnBannerWillPresentModalEventHandler);
		Vrtcal.OnBannerDidDismissModalEvent.AddListener(OnBannerDidDismissModalEventHandler);
		Vrtcal.OnBannerVideoStartedEvent.AddListener(OnBannerVideoStartedEventHandler);
		Vrtcal.OnBannerVideoCompletedEvent.AddListener(OnBannerVideoCompletedEventHandler);
		
		Vrtcal.OnInterstitialLoadedEvent.AddListener(OnInterstitialLoadedEventHandler);
		Vrtcal.OnInterstitialFailedToLoadEvent.AddListener(OnInterstitialFailedToLoadEventHandler);
		Vrtcal.OnInterstitialShownEvent.AddListener(OnInterstitialShownEventHandler);
		Vrtcal.OnInterstitialFailedToShowEvent.AddListener(OnInterstitialFailedToShowEventHandler);
		Vrtcal.OnInterstitialClickedEvent.AddListener(OnInterstitialClickedEventHandler);
		Vrtcal.OnInterstitialDismissedEvent.AddListener(OnInterstitialDismissedEventHandler);

		//Using Twitmore's App ID
		Vrtcal.InitSdk(11050); 
    }

    //Sdk Init Event Handlers
	public void OnSdkInitializedEventHandler(string reason) {
		Vrtcal.Log("Setting Pii Data");
		Vrtcal.SetPiiData("p", "867-5309");

        Vrtcal.Log("Requesting ads");
		Vrtcal.LoadTopBanner(bannerLive, 320, 50);
		Vrtcal.LoadBottomBanner(bannerDisplayTwitMore, 320, 50);
		Vrtcal.LoadInterstitial(interstitialDisplayTwitMore);		
    }

	public void OnSdkFailedToInitializeEventHandler(string reason) {
        Vrtcal.Log("Init failed: " + reason);
    }    


    //Banner Event Handlers
    public void OnBannerLoadedEventHandler(int zoneId, string reason) {
		Vrtcal.Log("zoneId: " + zoneId);
    }

    public void OnBannerFailedToLoadEventHandler(int zoneId, string reason) {
		Vrtcal.Log("zoneId: " + zoneId + " reason: " + reason);
    }

    public void OnBannerClickedEventHandler(int zoneId, string reason) {
		Vrtcal.Log("zoneId: " + zoneId);
    }

    public void OnBannerWillPresentModalEventHandler(int zoneId, string reason) {
		Vrtcal.Log("zoneId: " + zoneId);
    }

    public void OnBannerDidDismissModalEventHandler(int zoneId, string reason) {
		Vrtcal.Log("zoneId: " + zoneId);
    }

    public void OnBannerVideoStartedEventHandler(int zoneId, string reason) {
		Vrtcal.Log("zoneId: " + zoneId);
    }

    public void OnBannerVideoCompletedEventHandler(int zoneId, string reason) {
		Vrtcal.Log("zoneId: " + zoneId);
    }
 

	//Interstitial Event Handlers
    public void OnInterstitialLoadedEventHandler(int zoneId, string reason) {
		Vrtcal.Log("zoneId: " + zoneId);
		Vrtcal.ShowInterstitial(zoneId);
    }

    public void OnInterstitialFailedToLoadEventHandler(int zoneId, string reason) {
		Vrtcal.Log("zoneId: " + zoneId + " reason: " + reason);
    }
    
    public void OnInterstitialShownEventHandler(int zoneId, string reason) {
		Vrtcal.Log("zoneId: " + zoneId);
    }	
	
    public void OnInterstitialFailedToShowEventHandler(int zoneId, string reason) {
		Vrtcal.Log("zoneId: " + zoneId + " reason: " + reason);
    }
	
    public void OnInterstitialClickedEventHandler(int zoneId, string reason) {
		Vrtcal.Log("zoneId: " + zoneId);
    }
	
    public void OnInterstitialDismissedEventHandler(int zoneId, string reason) {
		Vrtcal.Log("zoneId: " + zoneId);
    }	
}