using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class KwaiAdsMgr
{
    public static void Init(string appId, string token, bool isDebug, Action<bool, int, string> initCallBack)
    {
        bool debug = isDebug; // Whether in debug mode. Plsease set to false when in release build.
        var kwaiAdConfig = new KwaiAds.Scripts.Api.KwaiAdConfig.Builder()
                .SetAppId(appId) // ±ØÌî
                .SetToken(token) // ±ØÌî
                .SetAppName("")
                .SetAppDomain("")
                .SetAppStoreUrl("")
                .SetDebugLog(debug)
                .Build();
        KwaiAds.Scripts.Api.KwaiAdsSdk.Initialize(kwaiAdConfig, new InitResultCallbackImpl(initCallBack));
    }

    class InitResultCallbackImpl : KwaiAds.Scripts.Api.InitResultCallback
    {
        private Action<bool, int, string> _initCallBack;

        public InitResultCallbackImpl(Action<bool, int, string> callBack)
        {
            _initCallBack = callBack;
        }

        public void OnFail(int code, string msg)
        {
            _initCallBack?.Invoke(false, code, msg);
            KwaiLog.Error($"#Kwai InitResultCallback code:{code}, msg: {msg}");
        }

        public void OnSuccess()
        {
            _initCallBack?.Invoke(true, 0, "");
            KwaiLog.Log($"#Kwai InitResultCallback OnSuccess.");
        }
    }

}

public class KwaiLog
{
    public static bool isShow = true;

    public static void Log(string msg)
    {
        if (isShow)
        {
            Debug.Log(msg);
        }
    }

    public static void Error(string msg)
    {
        if (isShow)
        {
            Debug.LogError(msg);
        }
    }

}
