using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Diagnostics;

public class MessageHandler : MonoBehaviour
{
    public Text resultInput;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void testHello()
    {
        // AndroidJavaClass jc = new AndroidJavaClass("com.aliyun.sls.android.plugin.unity.SLSAndroidAgent");
        // AndroidJavaObject jo = jc.CallStatic<AndroidJavaObject>("getInstance");
        // resultInput.text = "result from : " + jo.Call<string>("helloFromAndroid", "test_id");
        // jo.Call("initialize", "")

        Credentials credentials = new Credentials();
#if UNITY_IPHONE || UNITY_IOS
        credentials.instanceId = "ios-dev-ea64";
#elif UNITY_ANDROID
        credentials.instanceId = "androd-dev-f1a8";
#endif
        credentials.endpoint = "https://cn-hangzhou.log.aliyuncs.com";
        credentials.project = "yuanbo-test-1";
        credentials.accessKeyId = "";
        credentials.accessKeySecret = "";

        Unity4SLS.Initialize(credentials);

    }

    public void setExtra()
    {
        Unity4SLS.SetExtra("key1111", "value1111");
    }

    public void removeExtra()
    {
        Unity4SLS.RemoveExtra("key1111");
    }

    public void clearExtra()
    {
        Unity4SLS.ClearExtra();
    }

    public void setUserInfo()
    {
        UserInfo info = new UserInfo();
        info.uid = "12312123123123";
        info.channel = "dev_debug";
        info.ext.Add("u_key1", "u_value1");
        Unity4SLS.SetUserInfo(info);
    }


    public void testCrash()
    {
        Utils.ForceCrash(ForcedCrashCategory.AccessViolation);
    }

    public void reportCustomLog()
    {
        Debug.Log("[Unity4SLS] <DEBUG> - reportCustomLog.");
        Unity4SLS.ReportCustomLog("custom type", "custom log 1");
        Unity4SLS.ReportCustomLog("custom type", "custom log 2");
    }

    public void reportError()
    {
        Unity4SLS.ReportError("test stacktrace");
        Unity4SLS.ReportError("test type", "test stacktrace");
        Unity4SLS.ReportError("test type", "test message", "test stacktrace");
        Unity4SLS.ReportLuaError("test lua message", "test lua stacktrace");
        Unity4SLS.ReportCSharpError("test CSharp message", "test CSharp stacktrace");
    }

    public void credentialsCallback(string feature, string result)
    {
        // Console.WriteLine("[Unity4SLS] <DEBUG> - credentialsCallback. feature: {0}, result: {1}", feature, result);
        Debug.Log("[Unity4SLS] <DEBUG> - credentialsCallback. feature: " + feature + ", result: " +  result);

        Credentials credentials = new Credentials();
        credentials.accessKeyId = "";
        credentials.accessKeySecret = "";

        Unity4SLS.SetCredentials(credentials);
    }

    public void setCredentialsCallback()
    {
        callback_delegate callback = new callback_delegate(credentialsCallback);
        Unity4SLS.RegisterCredentialsCallback(callback);
    }
}
