#if UNITY_IOS

using System;
using System.Runtime.InteropServices;
using LitJson;
using UnityEngine;
using AOT;

namespace EngineSdkConverter.Unity.SDK
{
    class IOSUnityAdpter
    {
        [DllImport("__Internal")]
        internal static extern void InitSDK(string initEvent, string callback);

        [DllImport("__Internal")]
        internal static extern void SilentLogin(string callback);

        [DllImport("__Internal")]
        internal static extern void silentLoginWithParam(string loginEvent, string callback);

        [DllImport("__Internal")]
        internal static extern void LoginByType(string loginEvent, string callback);

        [DllImport("__Internal")]
        internal static extern void SendMobileCode(string loginEvent, string callback);

        [DllImport("__Internal")]
        internal static extern void Pay(string payParams, string callback);

        [DllImport("__Internal")]
        internal static extern void GetLocalProductInfo(string callback);

        [DllImport("__Internal")]
        internal static extern void SetPushResultHandler(string onReceive, string onClick);

        [DllImport("__Internal")]
        internal static extern void Logout(string callback);

        [DllImport("__Internal")]
        internal static extern void LogoutChannel(string loginType);

        [DllImport("__Internal")]
        internal static extern void AppsFlyerEventReport(string eventName, string reportEvent);

        [DllImport("__Internal")]
        internal static extern void GetAppsFlyerDeviceId(string callback);

        [DllImport("__Internal")]
        internal static extern void SetAppsFlyerCommonParam(string reportEvent);

        [DllImport("__Internal")]
        internal static extern void SetFirebaseUserProperty(string reportEvent);

        [DllImport("__Internal")]
        internal static extern void SetFirebaseCommonParam(string reportEvent);

        [DllImport("__Internal")]
        internal static extern void FirebaseEventReport(string eventName, string reportEvent);

        [DllImport("__Internal")]
        internal static extern void SetGDTCommonParam(string reportEvent);

        [DllImport("__Internal")]
        internal static extern void GDTEventReport(string eventName, string reportEvent);

        [DllImport("__Internal")]
        internal static extern void SetFirebaseCrashCustomKey(string info);

        [DllImport("__Internal")]
        internal static extern void ReportFirebaseCrashLog(string info);

        [DllImport("__Internal")]
        internal static extern void SetFirebaseCrashUserIdentifier(string info);

        [DllImport("__Internal")]
        internal static extern void ReportFirebaseCrashException(string info);

        [DllImport("__Internal")]
        internal static extern void CanBindList(string callback);

        [DllImport("__Internal")]
        internal static extern void AlreadyBindList(string callback);

        [DllImport("__Internal")]
        internal static extern void CheckBind(string loginType, string callback);
        
        [DllImport("__Internal")]
        internal static extern void CheckEmailBind(string loginType, string bindEvent, string callback);

        [DllImport("__Internal")]
        internal static extern void Bind(string bindEvent, string onGetSnsInfoFail, string onCheckSnsInfoFail, string onBindSnsInfoFail, string onBindSucc);

        [DllImport("__Internal")]
        internal static extern void GetBindUserList(string phoneNumber, string callback);

        [DllImport("__Internal")]
        internal static extern void GAProfileTrack(string reportEvent);

        [DllImport("__Internal")]
        internal static extern void GAEventTrack(string eventType, string eventName, string reportEvent);

        [DllImport("__Internal")]
        internal static extern void SetGACommonParam(string reportEvent);

        //TODO
        [DllImport("__Internal")]
        internal static extern void OnConfirm();

        //TODO
        [DllImport("__Internal")]
        internal static extern void OnCancel(string code, string errorInfo);

        [DllImport("__Internal")]
        internal static extern void RequestNotificationPermission();

        [DllImport("__Internal")]
        internal static extern void SetCertificationListener(string callback);

        [DllImport("__Internal")]
        internal static extern void Certificate(string certificationEventInfo, string callback);

        [DllImport("__Internal")]
        internal static extern void ReCertificate(string certificationEventInfo, string callback);

        [DllImport("__Internal")]
        internal static extern void RefreshCertification();

        [DllImport("__Internal")]
        internal static extern void SetServerLanguage(string languageType, string callback);

        //TODO
        [DllImport("__Internal")]
        internal static extern void GetDeviceId(string callback);

        [DllImport("__Internal")]
        internal static extern void LiveDetect(string yiDunEvent, string callback);

        [DllImport("__Internal")]
        internal static extern void GetYiDunCaptcha(string yiDunEvent, string callback);

        [DllImport("__Internal")]
        internal static extern void RequestWXAuthorize(string callback);

        [DllImport("__Internal")]
        internal static extern void GetWXAuthInfo(string callback);

        [DllImport("__Internal")]
        internal static extern void GetAPIVersion(string callback);

        [DllImport("__Internal")]
        internal static extern void Share(string shareEventInfo, string callback);

        [DllImport("__Internal")]
        internal static extern void SetPrivacy(string yiDunEventInfo, string callback);

        [DllImport("__Internal")]
        internal static extern void HasGeneratedGuest(string callback);

        [DllImport("__Internal")]
        internal static extern void ResetDouYinUserInfo(string douyinTrackInfo, string callback);

        [DllImport("__Internal")]
        internal static extern void ShowCollectUserInfo();

        [DllImport("__Internal")]
        internal static extern void ShowCollectThirdInfo();

        [DllImport("__Internal")]
        internal static extern void ShowAIHelp(string aihelpShowType);

        [DllImport("__Internal")]
        internal static extern void SetLoginUserInfo(string aihelpSetLoginUserInfoType);

        [DllImport("__Internal")]
        internal static extern void LogoutAIHelp();

        [DllImport("__Internal")]
        internal static extern void FetchAIHelpUnreadMessageCount();

        [DllImport("__Internal")]
        internal static extern void RegisterAIHelpEventListener(int aihelpEventType, string callback);

        [DllImport("__Internal")]
        internal static extern void UpdateServerUrl(string serverUrl);

        [DllImport("__Internal")]
        internal static extern void UpdateServerUrlList(string serverUrlList);

        [DllImport("__Internal")]
        internal static extern string GetCustomKeyValue(string key, string defaultValue);

        [DllImport("__Internal")]
        internal static extern void UpdatePassword(string loginEvent, string callback);

        [DllImport("__Internal")]
        internal static extern void RequestTrackingAuth(string callback);

        [DllImport("__Internal")]
        internal static extern void UnBind(string bindEvent, string callback);
    }
    public class IOSInterface : ISDKInterface
    {
        public delegate void CallbackWithParam(string param);
        [MonoPInvokeCallback(typeof(CallbackWithParam))]
        public static void SetDeliverResult(string param)
        {
            Debug.Log("SetDeliverResult------>in! result=" + param);
            Action onConfirm = () =>
            {
                IOSUnityAdpter.OnConfirm();
            };

            Action<string, string> onCancel = (code, errorInfo) =>
            {
                IOSUnityAdpter.OnCancel(code, errorInfo);
            };
            NativeCallBack.setDeliverResultCallback(param, onConfirm, onCancel);
        }

        public override void Init()
        {
            
        }

        //初始化
        public override void InitSDK(Action<string> callback)
        {
            InitEventBuilder.InitEvent initEvent = new InitEventBuilder.InitEvent();
            InitSDK(initEvent, callback);
        }

        // 个性化初始化
        public override void InitSDK(InitEventBuilder.InitEvent initEvent, Action<string> callback)
        {
            NativeCallBack.initResultCallback = callback;
            NativeCallBack.autoLogoutResultCallback = initEvent.autoLogoutCallback;
            initEvent.autoLogoutCallback = null; //AutoLogoutResult
            string initEventInfo = JsonMapper.ToJson(initEvent);
            IOSUnityAdpter.InitSDK(initEventInfo, "InitResult");
        }

        // 静默登录
        public override void SilentLogin(Action<string> callback)
        {
            NativeCallBack.silentLoginResultCallback = callback;
            IOSUnityAdpter.SilentLogin("SilentLoginResult");
        }

        public override void SilentLoginWithParam(LoginEventBuilder.LoginEvent loginEvent, Action<string> callback)
        {
            NativeCallBack.silentLoginResultCallback = callback;
            string loginEventInfo = JsonMapper.ToJson(loginEvent);
            NativeCallBack.callbacks["SilentLoginResult"] = callback;
            IOSUnityAdpter.silentLoginWithParam(loginEventInfo, "SilentLoginResult");
        }

        // 登录
        public override void LoginByType(LoginEventBuilder.LoginEvent loginEvent, Action<string> callback)
        {
            NativeCallBack.loginResultCallback = callback;
            string loginEventInfo = JsonMapper.ToJson(loginEvent);
            IOSUnityAdpter.LoginByType(loginEventInfo, "LoginResult");
        }

        // 验证码
        public override void SendCode(LoginEventBuilder.LoginEvent loginEvent, Action<string> callback)
        {
            NativeCallBack.sendCodeResultCallback = callback;
            string loginEventInfo = JsonMapper.ToJson(loginEvent);
            IOSUnityAdpter.SendMobileCode(loginEventInfo, "SendCodeResult");
        }

        // 支付
        public override void Pay(PayEventBuilder.PayEvent payEvent, Action<string> callback)
        {
            NativeCallBack.payResultCallback = callback;
            string payEventInfo = JsonMapper.ToJson(payEvent);
            IOSUnityAdpter.Pay(payEventInfo, "PayResult");
        }

        // 获取商品配置
        public override void GetLocalProductInfo(Action<string> callback)
        {
            NativeCallBack.getLocalProductInfoCallback = callback;
            IOSUnityAdpter.GetLocalProductInfo("GetLocalProductInfoResult");
        }

        // 设置推送回调
        public override void SetPushResultHandler(Action<string> onReceive, Action<string> onClick)
        {
            NativeCallBack.onPushResultReceiveCallback = onReceive;
            NativeCallBack.onPushResultClickCallback = onClick;
            IOSUnityAdpter.SetPushResultHandler("onPushResultReceive", "onPushResultClick");
        }

        // 退出登录
        public override void Logout(Action<string> callback)
        {
            NativeCallBack.logoutResultCallback = callback;
            IOSUnityAdpter.Logout("LogoutResult");
        }

        // 退出渠道登录
        public override void LogoutChannel(LoginEventBuilder.LoginEvent logoutEvent, Action<string> callback)
        {
            IOSUnityAdpter.LogoutChannel(logoutEvent.loginType);
        }

        // 设置AF上报
        public override void AppsFlyerEventReport(ReportEventBuilder.ReportEvent reportEvent)
        {
            string reportEventInfo = JsonMapper.ToJson(reportEvent.reportEvent);
            IOSUnityAdpter.AppsFlyerEventReport(reportEvent.eventName, reportEventInfo);
        }

        // 获取AF DeviceId
        public override void GetAppsFlyerDeviceId(Action<string> callback)
        {
            NativeCallBack.getAFDeviceIdCallback = callback;
            IOSUnityAdpter.GetAppsFlyerDeviceId("GetAFDeviceId");
        }

        // 设置AF通用参数 ok
        public override void SetAppsFlyerCommonParam(ReportEventBuilder.ReportEvent reportEvent)
        {
            string reportEventInfo = JsonMapper.ToJson(reportEvent.reportEvent);
            IOSUnityAdpter.SetAppsFlyerCommonParam(reportEventInfo);
        }
        // FB设置用户信息 ok
        public override void SetFirebaseUserProperty(ReportEventBuilder.ReportEvent reportEvent)
        {
            string reportEventInfo = JsonMapper.ToJson(reportEvent.reportEvent);
            IOSUnityAdpter.SetFirebaseUserProperty(reportEventInfo);
        }

        // FB设置通用参数 ok
        public override void SetFirebaseCommonParam(ReportEventBuilder.ReportEvent reportEvent)
        {
            string reportEventInfo = JsonMapper.ToJson(reportEvent.reportEvent);
            IOSUnityAdpter.SetFirebaseCommonParam(reportEventInfo);
        }

        // FB信息上报 ok
        public override void FirebaseEventReport(ReportEventBuilder.ReportEvent reportEvent)
        {
            string reportEventInfo = JsonMapper.ToJson(reportEvent.reportEvent);
            IOSUnityAdpter.FirebaseEventReport(reportEvent.eventName, reportEventInfo);
        }

        // 设置GDT通用参数 ok
        public override void SetGDTCommonParam(ReportEventBuilder.ReportEvent reportEvent)
        {
            string reportEventInfo = JsonMapper.ToJson(reportEvent.reportEvent);
            IOSUnityAdpter.SetGDTCommonParam(reportEventInfo);
        }

        // GDT事件上报 ok
        public override void GDTEventReport(ReportEventBuilder.ReportEvent reportEvent)
        {
            string reportEventInfo = JsonMapper.ToJson(reportEvent.reportEvent);
            IOSUnityAdpter.GDTEventReport(reportEvent.eventName, reportEventInfo);
        }

        public override void SetFirebaseCrashCustomKey(FirebaseCrashCustomKeyBuilder.FirebaseCrashCustomKeyType firebaseCrashCustomKey)
        {
            string firebaseCrashCustomKeyInfo = JsonMapper.ToJson(firebaseCrashCustomKey);
            IOSUnityAdpter.SetFirebaseCrashCustomKey(firebaseCrashCustomKeyInfo);
        }

        public override void ReportFirebaseCrashLog(FirebaseCrashLogBuilder.FirebaseCrashLogType firebaseCrashLog)
        {
            string firebaseCrashLogInfo = JsonMapper.ToJson(firebaseCrashLog);
            IOSUnityAdpter.ReportFirebaseCrashLog(firebaseCrashLogInfo);
        }

        public override void SetFirebaseCrashUserIdentifier(FirebaseCrashUserIdentifierBuilder.FirebaseCrashUserIdentifierType firebaseCrashUserIdentifier)
        {
            string firebaseCrashUserIdentifierInfo = JsonMapper.ToJson(firebaseCrashUserIdentifier);
            IOSUnityAdpter.SetFirebaseCrashUserIdentifier(firebaseCrashUserIdentifierInfo);
        }

        public override void ReportFirebaseCrashException(FirebaseCrashExceptionTypeBuilder.FirebaseCrashExceptionType firebaseCrashException)
        {
            string firebaseCrashExceptionInfo = JsonMapper.ToJson(firebaseCrashException);
            IOSUnityAdpter.ReportFirebaseCrashException(firebaseCrashExceptionInfo);
        }

        // 可绑定列表
        public override void CanBindList(Action<string> callback)
        {
            IOSUnityAdpter.CanBindList("CanBindListResult");
        }

        // 已绑定列表
        public override void AlreadyBindList(Action<string> callback)
        {
            IOSUnityAdpter.AlreadyBindList("AlreadyBindListResult");
        }

        // 绑定检查
        public override void Check(BindEventBuilder.BindEvent bindEvent, Action<string> callback)
        {
            NativeCallBack.checkResultCallback = callback;
            if (bindEvent.loginType.Equals(SDKType.EMAIL_CODE))
            {
                string bindEventInfo = JsonMapper.ToJson(bindEvent);
                IOSUnityAdpter.CheckEmailBind(bindEvent.loginType, bindEventInfo, "CheckResult");
            }
            else
            {
                IOSUnityAdpter.CheckBind(bindEvent.loginType, "CheckResult");
            }
        }

        // 绑定
        public override void Bind(BindEventBuilder.BindEvent bindEvent, Action<string> callback)
        {
            NativeCallBack.bindCallback = callback;
            string loginEventInfo = JsonMapper.ToJson(bindEvent);
            IOSUnityAdpter.Bind(loginEventInfo, "onGetSnsInfoFail", "onCheckSnsInfoFail", "onBindSnsInfoFail", "onBindSucc");
        }

        // 获取手机号绑定的用户列表
        public override void GetBindUserList(BindEventBuilder.BindEvent bindEvent, Action<string> callback)
        {
            NativeCallBack.bindCallback = callback;
            IOSUnityAdpter.GetBindUserList(bindEvent.phoneNumber, "UserBindListResult");
        }

        // 设置用户属性
        public override void GAProfileTrack(ReportEventBuilder.ReportEvent reportEvent)
        {
            string reportEventInfo = JsonMapper.ToJson(reportEvent);
            IOSUnityAdpter.GAProfileTrack(reportEventInfo);
        }

        // GA上报
        public override void GAEventTrack(ReportEventBuilder.ReportEvent reportEvent)
        {
            string reportEventInfo = JsonMapper.ToJson(reportEvent.reportEvent);
            IOSUnityAdpter.GAEventTrack(reportEvent.typeName, reportEvent.eventName, reportEventInfo);
        }

        // GA设置公共参数
        public override void SetGACommonParam(ReportEventBuilder.ReportEvent reportEvent)
        {
            string reportEventInfo = JsonMapper.ToJson(reportEvent.reportEvent);
            IOSUnityAdpter.SetGACommonParam(reportEventInfo);
        }

        // 申请通知权限
        public override void RequestNotificationPermission()
        {
            IOSUnityAdpter.RequestNotificationPermission();
        }

        // 设置防沉迷信息监听
        public override void SetCertificationListener(Action<string> callback)
        {
            NativeCallBack.setCertificationListenerCallback = callback;
            IOSUnityAdpter.SetCertificationListener("SetCertificationListener");
        }

        // 防沉迷
        public override void Certificate(CertificationEventBuilder.CertificationEvent certificationEvent, Action<string> callback)
        {
            NativeCallBack.certificationResultCallback = callback;
            string certificationEventInfo = JsonMapper.ToJson(certificationEvent);
            IOSUnityAdpter.Certificate(certificationEventInfo, "CertificationResult");
        }

        // 修改认证信息
        public override void ReCertificate(CertificationEventBuilder.CertificationEvent certificationEvent, Action<string> callback)
        {
            NativeCallBack.reCertificationResultCallback = callback;
            string certificationEventInfo = JsonMapper.ToJson(certificationEvent);
            IOSUnityAdpter.ReCertificate(certificationEventInfo, "ReCertificationResult");
        }

        // 刷新实名信息
        public override void RefreshCertification()
        {
            IOSUnityAdpter.RefreshCertification();
        }

        // 设置服务器返回语言
        public override void SetServerLanguage(string serverLanguage, Action<string> callback)
        {
            string action = "SetServerLanguageResult";
            NativeCallBack.callbacks[action] = callback;
            IOSUnityAdpter.SetServerLanguage(serverLanguage, action);
        }

        // 获取设备ID
        public override void GetDeviceId(Action<string> callback)
        {
            NativeCallBack.getDeviceIdResultCallback = callback;
            IOSUnityAdpter.GetDeviceId("GetDeviceIdResult");
        }


        // 人脸识别
        public override void LiveDetect(YiDunEventBuilder.YiDunEvent yiDunEvent, Action<string> callback)
        {
            NativeCallBack.liveDetectResultCallback = callback;
            string yiDunEventInfo = JsonMapper.ToJson(yiDunEvent);
            IOSUnityAdpter.LiveDetect(yiDunEventInfo, "LiveDetectResult");
        }

        // 行为验证码
        public override void GetYiDunCaptcha(YiDunEventBuilder.YiDunEvent yiDunEvent, Action<string> callback)
        {
            NativeCallBack.getYiDunCaptchaResultCallback = callback;
            string yiDunEventInfo = JsonMapper.ToJson(yiDunEvent);
            IOSUnityAdpter.GetYiDunCaptcha(yiDunEventInfo, "GetYiDunCaptchaResult");
        }

        // 微信授权
        public override void RequestWXAuthorize(Action<string> callback)
        {
            NativeCallBack.requestWXAuthorizeResultCallback = callback;
            IOSUnityAdpter.RequestWXAuthorize("RequestWXAuthorizeResult");
        }

        // 获取微信用户信息
        public override void GetWXAuthInfo(Action<string> callback)
        {
            NativeCallBack.getWXAuthInfoResultCallback = callback;
            IOSUnityAdpter.GetWXAuthInfo("GetWXAuthInfoResult");
        }

        // 获取SDK版本号
        public override void GetAPIVersion(Action<string> callback)
        {
            NativeCallBack.getAPIVersionResultCallback = callback;
            IOSUnityAdpter.GetAPIVersion("GetAPIVersionResult");
        }

        // 分享
        public override void Share(ShareEventBuilder.ShareEvent shareEvent, Action<string> callback)
        {
            NativeCallBack.shareResultCallback = callback;
            string shareEventInfo = JsonMapper.ToJson(shareEvent);
            IOSUnityAdpter.Share(shareEventInfo, "ShareResult");
        }

        // 隐私协议
        public override void SetPrivacy(YiDunEventBuilder.YiDunEvent yiDunEvent, Action<string> callback)
        {
            NativeCallBack.setPrivacyResultCallback = callback;
            string yiDunEventInfo = JsonMapper.ToJson(yiDunEvent);
            IOSUnityAdpter.SetPrivacy(yiDunEventInfo, "SetPrivacyResult");
        }

        // 是否存在游客账号
        public override void HasGeneratedGuest(Action<string> callback)
        {
            NativeCallBack.hasGeneratedGuestResultCallback = callback;
            IOSUnityAdpter.HasGeneratedGuest("HasGeneratedGuestResult");
        }

        // 抖音归因设置用户信息 ok
        public override void ResetUserInfo(DYTrackEventBuilder.DYTrackEvent dYTrackEvent, Action<string> callback)
        {
            NativeCallBack.resetUserInfoResultCallback = callback;
            string douyinTrackInfo = JsonMapper.ToJson(dYTrackEvent);
            IOSUnityAdpter.ResetDouYinUserInfo(douyinTrackInfo, "ResetUserInfoResult");
        }

        public override void ShowCollectUserInfo()
        {
            IOSUnityAdpter.ShowCollectUserInfo();
        }

        public override void ShowCollectThirdInfo()
        {
            IOSUnityAdpter.ShowCollectThirdInfo();
        }

        // 抖音归因获取用户信息
        public override void GetUserInfo(DYTrackEventBuilder.DYTrackEvent dYTrackEvent, Action<string> callback)
        {
            CallbackNotSupport(callback);
        }

        // 抖音归因获取直播信息 ok
        public override void GetLiveInfo(Action<string> callback)
        {
            CallbackNotSupport(callback);
        }

        // 单独设置配置参数 ok
        public override void SetConfig(ConfigEventBuilder.ConfigEvent configEvent, Action<string> callback)
        {
            CallbackNotSupport(callback);
        }

        // 是否微信安装 ok
        public override void IsWxInstalled(Action<string> callback)
        {
            CallbackNotSupport(callback);
        }
        // ————————————————————————————————————————————

        // 国内渠道登录 ok
        public override void Login(Action<string> callback)
        {
            CallbackNotSupport(callback);
        }

        // 获取支付方式列表
        public override void Charge(PayEventBuilder.PayEvent payEvent, Action<string> callback)
        {
            CallbackNotSupport(callback);
        }

        // 退出游戏
        public override void ExitGame(Action<string> callback)
        {
            CallbackNotSupport(callback);
        }

        // 设置默认分享信息
        public override void SetDefaultShareInfo(ShareEventBuilder.ShareEvent shareEvent, Action<string> callback)
        {
            CallbackNotSupport(callback);
        }

        private void CallbackNotSupport(Action<string> callback)
        {
            //TODO: 回调不支持
            throw new NotImplementedException();
        }

        // 设置发货回调
        public override void SetLocalDeliverListener(Action<string, Action, Action<string, string>> callback)
        {
            CallbackNotSupport(null);
        }

        public override void GetShareInfoFromMarketService(Action<string> callback)
        {
            CallbackNotSupport(null);
        }

        public override void GetAdInfoFromMarketService(Action<string> callback, Action<string> newCallback)
        {
            CallbackNotSupport(null);
        }

        public override void TxAdSDKReport(TxAdSDKReportEventBuilder.TxAdSDKReportEvent txAdSDKReportEvent)
        {
            CallbackNotSupport(null);
        }

        public override void SetWxUserInfo(SetWxUserInfoEventBuilder.SetWxUserInfoEvent setWxUserInfoEvent, Action<string> callback)
        {
            CallbackNotSupport(null);
        }

        public override void ShowAIHelp(AIHelpShowTypeBuilder.AIHelpShowType aihelpShowType)
        {
            IOSUnityAdpter.ShowAIHelp(JsonMapper.ToJson(aihelpShowType));
        }

        public override void SetLoginUserInfo(AIHelpSetLoginUserInfoTypeBuilder.AIHelpSetLoginUserInfoType aihelpSetLoginUserInfoType)
        {
            IOSUnityAdpter.SetLoginUserInfo(JsonMapper.ToJson(aihelpSetLoginUserInfoType));
        }

        public override void LogoutAIHelp()
        {
            IOSUnityAdpter.LogoutAIHelp();
        }

        public override void FetchAIHelpUnreadMessageCount()
        {
            IOSUnityAdpter.FetchAIHelpUnreadMessageCount();
        }

        public override void RegisterAIHelpEventListener(AiHelpEventType aihelpEventType, Action<string, object> callback)
        {
            Action<string> outCallback = (param) =>
            {
                callback(param, null);
            };
            string key = "registerAiHelpAsyncEventListener_" + aihelpEventType.ToString();
            NativeCallBack.callbacks[key] = outCallback;
            IOSUnityAdpter.RegisterAIHelpEventListener((int)aihelpEventType, key);
        }

        public override void UpdateServerUrl(string serverUrl)
        {
            IOSUnityAdpter.UpdateServerUrl(serverUrl);
        }

        public override void UpdateServerUrlList(string[] serverUrlList)
        {
            IOSUnityAdpter.UpdateServerUrlList(JsonMapper.ToJson(serverUrlList));
        }

        public override string GetCustomKeyValue(string key, string defaultValue)
        {
            return IOSUnityAdpter.GetCustomKeyValue(key, defaultValue);
        }

        public override void UpdatePassword(LoginEventBuilder.LoginEvent loginEvent, Action<string> callback)
        {
            string action = "updatePassword";
            NativeCallBack.callbacks[action] = callback;
            string loginEventInfo = JsonMapper.ToJson(loginEvent);
            IOSUnityAdpter.UpdatePassword(loginEventInfo, action);
        }

        public override void RequestTrackingAuthorization(Action<string> callback)
        {
            string action = "RequestTrackingAuthorizationResult";
            NativeCallBack.callbacks[action] = callback;
            IOSUnityAdpter.RequestTrackingAuth(action);
        }

        public override void UnBind(BindEventBuilder.BindEvent bindEvent, Action<string> callback)
        {
            string action = "unBind";
            NativeCallBack.callbacks[action] = callback;
            string bindEventInfo = JsonMapper.ToJson(bindEvent);
            IOSUnityAdpter.UnBind(bindEventInfo, action);
        }
    }
}

#endif