using System;
using UnityEngine;

namespace TyphoonUnitySDK
{
    /// <summary>
    /// 微游sdk
    /// </summary>
    public class MiniGameSdk : BaseSdk
    {
        private MiniGameAdsControl AdsControl { get; set; }

        public override void OnCreate()
        {
            SdkDebug.Log("on create ...");
            var callBackObj = new GameObject("ScriptControl");
            AdsControl = callBackObj.AddComponent<MiniGameAdsControl>();
            GameObject.DontDestroyOnLoad(callBackObj);
            if (SdkLite.MiniGameLifecycle == null)
            {
                SdkDebug.Log("create MiniGameLifecycle");
                //构建生命周期默认处理函数
                SdkLite.OverrideMiniGameLifecycle(new MiniGameLifecycle());
            }

            SdkDebug.Log("on create success!");
        }

        public override void InitSdk(Action success, Action<string> fail)
        {
            SdkDebug.Log("init sdk default success");
            success?.Invoke();
        }

        public override void Login(Action success, Action<string> fail)
        {
            SdkDebug.Log("login default success");
            success?.Invoke();
        }

        public override void ShowBanner(string scene, BannerPosition position)
        {
            SdkDebug.Log($"ShowBanner {scene} position: {position}");
            AdsControl.showBannerAd();
        }

        public override void HideBanner(string scene = "")
        {
            SdkDebug.Log($"HideBanner scene = {scene} ");
            AdsControl.hideBannerAd();
        }


        public override bool GetVideoFlag()
        {
            return true;
        }

        public override void ShowVideo(string scene, Action success, Action<string> fail)
        {
            SdkDebug.Log($"ShowVideo scene = {scene} ");
            AdsControl.ShowVideo(success, fail);
        }

        public override void ShowInters(string scene)
        {
            SdkDebug.Log($"ShowInters scene = {scene} ");
            AdsControl.showInterstitialAd();
        }
    }
}