#if UNITY_ANDROID
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Touka
{
    /// 
    /// TKG Native SDK Android platform interface call
    /// 
    public class TKGNativeInterfaceAndroid : TKGNativeInterface
    {
        private AndroidJavaObject jo;
        public TKGNativeInterfaceAndroid()
        {
            // java interface class
            using (AndroidJavaClass jc = new AndroidJavaClass("com.touka.tkg.TKGProxyJava"))
            {
                jo = jc.CallStatic("getInstance");
            }
        }
        private T SDKCall(string _method, params object[] _param)
        {
            try
            {
                return jo.Call(_method, _param);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
            return default(T);
        }
        private void SDKCall(string _method, params object[] _param)
        {
            try
            {
                jo.Call(_method, _param);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
        }
#region init
        /// 
        /// init
        /// 
        /// 
        public override void Init(Action _initCallback = null)
        {
            Debug.Log("init ----- 00");
            base.Init(_initCallback);
            Debug.Log("init ----- 01");
            SetBannerAdCallback(new AndroidBannerADTKGAdCallback());
            Debug.Log("init ----- 01 ------- a");
            setInterstitalAdCallback(new AndroidInterADTKGAdCallback());
            Debug.Log("init ----- 01 ------- b");
            SetRewardAdCallback(new AndroidRewardADTKGAdCallback());
            Debug.Log("init ----- 01 ------- c");
            SDKCall("init", new AndroidProxyCallback());
            Debug.Log("init ----- 02");
        }
#endregion
        /// 
        /// Get Channel
        /// 
        /// 
        public override string GetChannel()
        {
            return SDKCall("getChannel");
        }
#region Ads
#region Ads Show
        /// 
        /// Show banner Ad
        /// 
        ///  banner pos, 1:Top;2:Bottom 
        public override void showBannerAd(int _pos)
        {
            SDKCall("showBannerAd", _pos);
        }
        /// 
        /// Hide Banner Ad
        /// 
        public override void hideBannerAd()
        {
            SDKCall("hideBannerAd");
        }
        /// 
        /// Show Interstitial Ad
        /// 
        public override void showInterstitialAd()
        {
            SDKCall("showInterstitialAd");
        }
        /// 
        /// Show Interstitial Ad
        /// 
        /// 
        public override void showInterstitialAd(string _adPos, IVADType _IvType = IVADType.IV1)
        {
            SDKCall("showInterstitialAd", _adPos, (int)_IvType);
        }
        /// 
        /// Show Reward Ad
        /// 
        /// 
        /// 
        public override void showRewardAd(string _adPos, int _itemCount = -1)
        {
            SDKCall("showRewardAd", _adPos, _itemCount);
        }
        /// 
        /// Show Reward Ad
        /// 
        /// 
        /// 
        /// 
        public override void showRewardAd(string _adPos, int _itemCount, Dictionary _extraEvent)
        {
            SDKCall("showRewardAd", _adPos, _itemCount, _extraEvent);
        }
        /// 
        /// Show Video Ad
        /// 
        /// 
        /// 
        public override void showVideoAd(string _adPos, int _itemCount = -1)
        {
            SDKCall("showVideoAd", _adPos, _itemCount);
        }
#endregion
#region Ads isready
        /// 
        /// banner isReady
        /// 
        /// 
        public override bool isBannerAdReady()
        {
            bool isReady = SDKCall("isBannerAdReady");
            return isReady;
        }
        /// 
        /// Interstitial isReady
        /// 
        /// 
        public override bool isInterstitialAdReady()
        {
            bool isReady = SDKCall("isInterstitialAdReady");
            return isReady;
        }
        /// 
        /// Reward isReady
        /// 
        /// 
        public override bool isRewardAdReady()
        {
            bool isReady = SDKCall("isRewardAdReady");
            return isReady;
        }
        /// 
        /// FullScreen isReady
        /// 
        /// 
        public override bool isVideoAdReady()
        {
            bool isReady = SDKCall("isVideoAdReady");
            return isReady;
        }
#endregion
#region Set ads callback
        /// 
        /// Set Banner Ad Callback
        /// 
        /// 
        public override void SetBannerAdCallback(AndroidBannerADTKGAdCallback _bannerCallback)
        {
            SDKCall("setBannerAdCallback", _bannerCallback);
        }
        /// 
        /// Set Interstital Ad Callback
        /// 
        /// 
        public override void setInterstitalAdCallback(AndroidInterADTKGAdCallback _interCallback)
        {
            SDKCall("setInterstitalAdCallback", _interCallback);
        }
        /// 
        /// Set reward Ad Callback
        /// 
        /// 
        public override void SetRewardAdCallback(AndroidRewardADTKGAdCallback _rewardCallback)
        {
            SDKCall("setRewardAdCallback", _rewardCallback);
        }
        /// 
        /// Set video Ad Callback(full screen ad, reward ad with no reward callback)
        /// 
        /// 
        public override void setVideoAdCallback(AndroidInterADTKGAdCallback _videoCallback)
        {
            SDKCall("setVideoAdCallback", _videoCallback);
        }
#endregion
#region load ads
        /// 
        /// load interstitial ad
        /// (retry 3 times, per time interval 10s)
        /// 
        public override void loadInterstitialAD()
        {
            SDKCall("loadInterstitialAD");
        }
        /// 
        /// load reward ad
        /// (retry 3 times, per time interval 10s)
        /// 
        public override void loadRewardAD()
        {
            SDKCall("loadRewardAD");
        }
        /// 
        /// load video ad
        /// (retry 3 times, per time interval 10s)
        /// 
        public override void loadVideoAD()
        {
            SDKCall("loadVideoAD");
        }
#endregion
#endregion
#region Log Event
#region Normal
        /// 
        /// onEvent
        /// 
        /// 
        /// 
        public override void onEvent(string _eventName)
        {
            SDKCall("onEvent", _eventName);
        }
        /// 
        /// onEvent
        /// 
        /// 
        /// 
        /// 
        /// 
        public override void onEvent(string _eventName, string _key01, string _value01)
        {
            SDKCall("onEvent", _eventName, _key01, _value01);
        }
        /// 
        /// onEvent
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public override void onEvent(string _eventName, string _key01, string _value01, string _key02, string _value02)
        {
            SDKCall("onEvent", _eventName, _key01, _value01, _key02, _value02);
        }
        /// 
        /// onEvent
        /// 
        /// 
        /// 
        public override void onEvent(string _eventName, Dictionary _keyValues)
        {
            SDKCall("onEvent", _eventName, Analytics.ToJavaHashMap(_keyValues));
        }
#endregion
#region Level Event
        /// 
        /// Level Start
        /// 
        /// 
        public override void LevelStart(string _levelId)
        {
            SDKCall("levelStart", _levelId);
        }
        /// 
        /// Level end
        /// 
        /// 
        public override void LevelEnd(string _levelId, bool _isSucc)
        {
            SDKCall("levelEnd", _levelId, _isSucc);
        }
#endregion
#region Tracking Event
        /// 
        /// Log Tracking Event
        /// 
        /// 
        public override void LogTrackingEvent(TrackingEventType _eventType)
        {
            SDKCall("LogTrackingEvent", (int)_eventType);
        }
#endregion
#endregion
#region Online Config
        /// 
        /// get config - int
        /// 
        /// 
        /// 
        /// 
        public override int GetConfigInt(string _key, int _defaultValue)
        {
            Debug.Log("int _key : " + _key + " , _defaultValue : " + _defaultValue);
            int newValue = SDKCall("getConfigInt", _key, _defaultValue);
            return newValue;
        }
        /// 
        /// get config - string
        /// 
        /// 
        /// 
        /// 
        public override string GetConfigString(string _key, string _defaultValue)
        {
            Debug.Log("string _key : " + _key + " , _defaultValue : " + _defaultValue);
            string newValue = SDKCall("getConfigString", _key, _defaultValue);
            return newValue;
        }
        /// 
        /// get config - bool
        /// 
        /// 
        /// 
        /// 
        public override bool GetConfigBool(string _key, bool _defaultValue)
        {
            Debug.Log("bool _key : " + _key + " , _defaultValue : " + _defaultValue);
            bool newValue = SDKCall("getConfigBool", _key, _defaultValue);
            return newValue;
        }
#endregion
#region Others (Common)
        /// 
        /// review
        /// 
        public override void Review()
        {
            SDKCall("review");
        }
        /// 
        /// open Privacy
        /// 
        public override void OpenPrivacyURL()
        {
            SDKCall("openPrivacy");
        }
        /// 
        /// open agreement
        /// 
        public override void OpenUserTermURL()
        {
            SDKCall("openAgreement");
        }
        /// 
        /// open policy pop
        /// 
        public override void OpenPolicyPop()
        {
            SDKCall("openPrivacyDialog");
        }
        /// 
        /// More Games
        /// 
        public override void OpenMoreGame()
        {
            SDKCall("moreGames");
        }
#endregion
#region Others (Uncommon)
        /// 
        /// shake(no repeat)
        /// 
        ///  shake time 
        public override void shake(int _shakeType, float _intensity = 1)
        {
            long tShakeMS = _shakeType * _shakeType * 20 + (int)(_intensity * (_shakeType + 1) * 10);
            SDKCall("shake", tShakeMS);
        }
        /// 
        /// shake(can repeat)
        /// 
        ///  repeat times : -1 
        ///  wait time,shake time(100,1000,100,111)
        //public override void shake(int _repeatTimes, params int[] _shakeTime)
        //{
        //    SDKCall("shake", _repeatTimes, _shakeTime);
        //}
        /// 
        /// cancel shake
        /// 
        public override void cancelShake()
        {
            SDKCall("cancelShake");
        }
        /// 
        /// Show Tips
        /// Pop-up prompt (the one with black transparent background) unified style, Chinese, Japanese, Korean and English, support multi-language, multi-language text
        ///
        /// game judges different languages by itself and passes different strings
        /// 
        ///  title 
        ///  content 
        public override void dialogTips(string _titleStr, string _contentStr = "")
        {
            SDKCall("dialogTips", _titleStr);
        }
        /// 
        /// Open ULR by Browser
        /// 
        /// 
        public override void openUrlBrowser(string _url)
        {
            SDKCall("openUrlBrowser", _url);
        }
        /// 
        /// Open ULR By WEB POP
        /// 
        /// 
        public override void openWebUrl(string _url)
        {
            SDKCall("openWebUrl", _url);
        }
        /// 
        /// show Toast
        /// 
        /// 
        public override void toast(string _content)
        {
            SDKCall("toast");
        }
        /// 
        /// push message
        /// 
        public override void pushMsg()
        {
            SDKCall("pushMsg");
        }
#endregion
    }
}
#endif