package com.rninstabugsdk.rninstabugsdk;

import com.instabug.library.Instabug;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.Promise;

import java.util.HashMap;

public class InstabugSDKModule extends ReactContextBaseJavaModule {

  // Invocation Events
  private final String INVOCATION_EVENT_NONE = "none";
  private final String INVOCATION_EVENT_SHAKE = "shake";
  private final String INVOCATION_EVENT_SCREENSHOT = "screenshot";
  private final String INVOCATION_EVENT_TWO_FINGERS_SWIPE = "swipe";
  private final String INVOCATION_EVENT_FLOATING_BUTTON = "button";

  // Invocation Modes
  private final String INVOCATION_MODE_NEW_BUG = "bug";

  // NOTE(mark): In this version of the SDK, feature -> feedback.
  private final String INVOCATION_MODE_NEW_FEATURE = "feedback";

  public InstabugSDKModule(ReactApplicationContext reactContext) {
    super(reactContext);
  }

  @Override
  public String getName() {
    return "RNInstabugSDK";
  }

  @ReactMethod
  public void startWithToken(String token, String invocationEvent) {
    // TODO
  }

  @ReactMethod
  public void invoke() {
    // TODO
  }

  @ReactMethod
  public void invokeWithInvocationMode(String invocationMode) {
    // TODO
  }

  @ReactMethod
  public void dismiss() {
    // TODO
  }

  @ReactMethod
  public void setIntroMessageEnabled(boolean isEnabled) {
    // TODO
  }

  @ReactMethod
  public void setUserData(String userData) {
    // TODO
  }

  @ReactMethod
  public void setUserEmail(String userName) {
    // TODO
  }

  @ReactMethod
  public void setEmailFieldRequired(boolean isRequired) {
    // TODO
  }

  @ReactMethod
  public void setCommentFieldRequired(boolean isRequired) {
    // TODO
  }

  @ReactMethod
  public void resetTags() {
    // TODO
  }

  @Override
  public Map<String, Object> getConstants() {
    final Map<String, Object> constants = new HashMap<>();

    // Invocation Events
    // TODO(mark): iOS has invocationEventRightEdgePan which Android doesn't
    // have.
    constants.put("invocationEventNone", INVOCATION_EVENT_NONE);
    constants.put("invocationEventShake", INVOCATION_EVENT_SHAKE);
    constants.put("invocationEventScreenshot", INVOCATION_EVENT_SCREENSHOT);
    constants.put("invocationEventTwoFingersSwipe", INVOCATION_EVENT_TWO_FINGERS_SWIPE);
    constants.put("invocationEventFloatingButton", INVOCATION_EVENT_FLOATING_BUTTON);

    // Invocation Modes
    // TODO(mark): iOS has invocationModeNA which Android doesn't have.
    constants.put("invocationModeNewBug", INVOCATION_MODE_NEW_BUG);
    constants.put("invocationModeNewFeature", INVOCATION_MODE_NEW_FEATURE);

    return constants;
  }

}

@@ -72,16 +72,143 @@
 nstabug;
+%0Aimport com.instabug.library.invocation.InstabugInvocationEvent;%0Aimport com.instabug.library.invocation.InstabugInvocationMode;
 %0A%0Aimport
@@ -977,65 +977,8 @@
 des%0A
-  private final String INVOCATION_MODE_NEW_BUG = %22bug%22;%0A%0A
   //
@@ -1086,28 +1086,157 @@
 NEW_
-FEATURE = %22feedback%22
+BUG = %22bug%22;%0A  private final String INVOCATION_MODE_NEW_FEATURE = %22feedback%22;%0A%0A  // Instance of the Instabug SDK object.%0A  private Instabug mInstabug
 ;%0A%0A 
@@ -1484,39 +1484,245 @@
 ionEvent) %7B%0A    
-// TODO
+mInstabug = new Instabug.Builder(this.androidApplication, androidToken);%0A    mInstabug.setIntroMessageEnabled(false)%0A    mInstabug.setInvocationEvent(getInvocationEventById(invocationEvent))%0A    mInstabug.build();
 %0A  %7D%0A%0A  @ReactMe
@@ -3295,10 +3295,1147 @@
 s;%0A  %7D%0A%0A
+  // --------------------------------------------------%0A  // Private%0A  // --------------------------------------------------%0A  private InstabugInvocationEvent getInvocationEventById(String invocationEventValue) %7B%0A    InstabugInvocationEvent invocationEvent = InstabugInvocationEvent.SHAKE;%0A    try %7B%0A      if (invocationEventValue.equals(INVOCATION_EVENT_FLOATING_BUTTON)) %7B%0A        invocationEvent = InstabugInvocationEvent.FLOATING_BUTTON;%0A      %7D else if (invocationEventValue.equals(INVOCATION_EVENT_TWO_FINGERS_SWIPE)) %7B%0A        invocationEvent = InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT;%0A      %7D else if (invocationEventValue.equals(INVOCATION_EVENT_SHAKE)) %7B%0A        invocationEvent = InstabugInvocationEvent.SHAKE;%0A      %7D else if (invocationEventValue.equals(INVOCATION_EVENT_SCREENSHOT)) %7B%0A        invocationEvent = InstabugInvocationEvent.SCREENSHOT_GESTURE;%0A      %7D else if (invocationEventValue.equals(INVOCATION_EVENT_NONE)) %7B%0A        invocationEvent = InstabugInvocationEvent.NONE;%0A      %7D%0A%0A      return invocationEvent;%0A    %7D catch (Exception e) %7B%0A      e.printStackTrace();%0A      return invocationEvent;%0A    %7D%0A  %7D%0A%0A
 %7D%0A

Add way to get the invocation event and turn it into the Instabug constant