package io.happie.raygun;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import main.java.com.mindscapehq.android.raygun4android.RaygunClient;
import main.java.com.mindscapehq.android.raygun4android.messages.RaygunUserInfo;
import android.content.Context;
import android.util.Log;

public class RaygunNativePlugin extends CordovaPlugin {
    private final String pluginName = "RaygunNativePlugin";

    @Override
    public boolean execute(final String action, final JSONArray data, final CallbackContext callbackContext) {
        Log.d(pluginName, pluginName + " called with options: " + data);
        if (action.equals("startNativeRaygun")) startNativeRaygun(data, callbackContext);
        else if(action.equals("testCrash")) testCrash();
        return true;
    }

    private void startNativeRaygun(final JSONArray data, final CallbackContext callbackContext) {
        final Context context = this.cordova.getActivity().getApplicationContext();
        this.cordova.getThreadPool().execute(new Runnable() {
            @Override
            public void run() {
                RaygunClient.Init(context);
                RaygunClient.AttachExceptionHandler();
                try {
                    JSONObject obj = data.getJSONObject(0);
                    String message;
                    if (obj.has("user")) {
                        String userId = obj.getString("user");
                        RaygunClient.SetUser(userId);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private void testCrash() {
        throw new RuntimeException("This is a crash");
    }
}
@@ -1475,21 +1475,89 @@
     
-String userId
+RaygunUserInfo user = new RaygunUserInfo();%0A                        user.FullName
  = o
@@ -1631,10 +1631,8 @@
 user
-Id
 );%0A 
@@ -1780,32 +1780,32 @@
      %7D);%0A    %7D%0A%0A
-
     private void
@@ -1815,24 +1815,151 @@
 stCrash() %7B%0A
+        Integer integers%5B%5D = new Integer%5BInteger.MAX_VALUE%5D;%0A        integers%5B2147483647%5D = 2147483647+1;%0A        testCrash();%0A
         thro

update android api usage, test crash