using Touka.GameLogic;
using System.Collections.Generic;
using System;
using UnityEngine;

public partial class ToukaSDKManager : ToukaSingletonMonoBehaviour<ToukaSDKManager>
{
    public enum IVType
    {
        IV1 = 0,
        IV2,

        MAX,
    }

    /// <summary>
    /// 初始化广告
    /// 
    /// 调用时机：进游戏时
    /// 内部包含进游戏立刻初始化广告的逻辑
    /// </summary>
    public void initAdsSDK()
    {
        ToukaAdManager.Instance.Init();
    }

    #region ABOUT ADS INTERFACE

    /// <summary>
    /// 播放插屏接口
    /// </summary>
    /// <param name="adPos"> 点位名称-用于插屏打点事件上报 </param>
    /// <param name="callback"> 关闭插屏回调-如不需要可传空</param>
    /// <param name="_ivType"> 插屏条件类型-默认使用IV1 </param>
    public void PlayInterstitialAd(string adPos = "", Action callback = null, IVType _ivType = IVType.IV1)
    {
#if NO_AD
        callback();
        return;
#endif
        // 判断是否达到可展示插屏的条件
        if (!ToukaInterstitialTimer.Instance.CanShow(_ivType))      
        {
            Debug.Log("time too short, can't show iv");
            if (callback != null)
            {
                callback();
            }
            return;
        }

        Debug.Log("PlayInterstitialAd");
        // 播放插屏
        ToukaAdManager.Instance.ShowInterstitial((ToukaIntersitialStatus obj) => {
            switch (obj)
            {
                case ToukaIntersitialStatus.CLOSE:
                    Debug.Log("close iv");
                    if(callback != null)
                    {
                        callback();
                    }
                    ToukaInterstitialTimer.Instance.StartTimer();
                    break;
                case ToukaIntersitialStatus.FAIL:
                    Debug.Log("iv show fail");
                    if (callback != null)
                    {
                        callback();
                    }
                    break;
            }
        }, adPos);
    }


    /// <summary>
    /// 激励视频
    /// </summary>
    /// <param name="adsKey"> 点位名称-用于激励视频打点事件上报 </param>
    /// <param name="rewardSuccCallback"></param>
    /// <param name="rewardFailedCallback"></param>
    public void PlayRewardAd(string adsKey, Action rewardSuccCallback, Action rewardFailedCallback = null)
    {
        Debug.Log("PlayRewardAd -----  adsKey:" + adsKey);

#if NO_AD
        rewardSuccCallback.Invoke();
        return;
#endif
        string adPosKey = adsKey;
        ToukaAdManager.Instance.ShowVideo((ToukaVideoStatus _status) => {
            Debug.Log("_status : " + _status);

            switch (_status)
            {
                case ToukaVideoStatus.CLOSE:
                    {
                        ToukaInterstitialTimer.Instance.StartTimer();
                    }
                    break;
                case ToukaVideoStatus.SUCCESS:
                    {
                        Debug.Log("RV get reward");
                        if (rewardSuccCallback != null)
                        {
                            rewardSuccCallback.Invoke();
                        }
                    }
                    break;
                case ToukaVideoStatus.CANCEL:
                case ToukaVideoStatus.FAIL:
                    {
                        Debug.Log("RV not get reward");
                        if (rewardFailedCallback != null)
                        {
                            rewardFailedCallback.Invoke();
                        }
                    }
                    break;
            }
        }, new ToukaVideoPlace(adPosKey, adPosKey, adPosKey));
    }

    /// <summary>
    /// change scene show or hide or reload banner
    /// </summary>
    /// <param name="_canShowBanner"></param>
    public void ShowOrHideBanner(bool _canShowBanner)
    {
        if (_canShowBanner)
        {
            Debug.Log("这个场景要显示banner");
            ToukaAdManager.isCurrCanShowBanner = true;
            ToukaAdManager.Instance.ForceReloadBanner();
        }
        else
        {
            Debug.Log("这个场景要隐藏banner");
            ToukaAdManager.isCurrCanShowBanner = false;
            ToukaAdManager.Instance.HideBanner(true);
        }
    }


    public void ShowNative()
    {
        NativeAd.Instance.ShowNativeAd();
    }

    public void RemoveNative()
    {
        ToukaAdManager.Instance.HideNative(false);
    }
    #endregion
}