﻿using UnityEngine;
using EasyCoppa;

public class Demo_Handler : MonoBehaviour {

    [SerializeField] EC_Lang localization;

    private void OnEnable()
    {
        EC_Dialog.onCoppaDialogCompleted += onCoppaDialogCompleted;
        EC_Dialog.onDefaultDialogCompleted += onDefaultDialogCompleted;
        EC_Dialog.onPlayerOpenedPrivacyURL += onPlayerOpenedPrivacyURL;
        EC_Dialog.onPlayerOpenedTermsURL += onPlayerOpenedTermsURL;
    }

    private void OnDisable()
    {
        EC_Dialog.onCoppaDialogCompleted -= onCoppaDialogCompleted;
        EC_Dialog.onDefaultDialogCompleted -= onDefaultDialogCompleted;
        EC_Dialog.onPlayerOpenedPrivacyURL -= onPlayerOpenedPrivacyURL;
        EC_Dialog.onPlayerOpenedTermsURL -= onPlayerOpenedTermsURL;
    }

    public void GUI_ShowDialog()
    {
        EC_Dialog.ShowDialog();
    }

    public void GUI_SetLocalization()
    {
        EC_Settings.SetTranslation(localization);
        EC_Dialog.RefreshLocalization();
    }

    private void onDefaultDialogCompleted()
    {
        Debug.Log("The player accepted the terms of use");
    }

    private void onCoppaDialogCompleted(EC_Dialog.EC_DialogResult result)
    {
        Debug.Log("The player accepted the terms of use");

        switch (result)
        {
            case EC_Dialog.EC_DialogResult.EC_UNDERAGE:
                Debug.Log("The player is underage");
                //Since the player is underage you should not initialize any tool that might track the player
                break;

            case EC_Dialog.EC_DialogResult.EC_NOT_UNDERAGE:
                Debug.Log("The player is not underage");
                //Since the player is not underage it should be safe to initialize any tracking tool
                break;

            case EC_Dialog.EC_DialogResult.EC_REJECTED:
                Debug.Log("The player was underage and therefore rejected");
                //EC_Settings defined that underage players should be rejected
                break;
        }        
    }

    private void onPlayerOpenedPrivacyURL()
    {
        //You might want to use this event for Analytics purposes
        Debug.Log("The player opened a browser page for the privacy policy");
    }

    private void onPlayerOpenedTermsURL()
    {
        //You might want to use this event for Analytics purposes
        Debug.Log("The player opened a browser page for the terms of use");
    }
}
