package za.co.io.sentry;

import com.facebook.react.bridge.Promise;
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.getsentry.raven.android.Raven;
import com.getsentry.raven.event.Event.Level;
import com.getsentry.raven.event.EventBuilder;
import com.getsentry.raven.event.interfaces.ExceptionInterface;

import java.util.HashMap;
import java.util.Map;

public final class ReactNativeSentryAndroidModule extends ReactContextBaseJavaModule {

  public ReactNativeSentryAndroidModule(ReactApplicationContext rctx) {
    super(rctx);
    Raven.init(rctx);
  }

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

  @Override
  public Map<String, Object> getConstants() {
    final Map<String, Object> constants = new HashMap<>();
    constants.put("SENTRY_EVENT_LEVEL_FATAL", Level.FATAL);
    constants.put("SENTRY_EVENT_LEVEL_ERROR", Level.ERROR);
    constants.put("SENTRY_EVENT_LEVEL_WARNING", Level.WARNING);
    constants.put("SENTRY_EVENT_LEVEL_INFO", Level.INFO);
    constants.put("SENTRY_EVENT_LEVEL_DEBUG", Level.DEBUG);
    return constants;
  }

  private static final Level getLevel(final String level) {
    if (level == null || level.isEmpty()) return Level.DEBUG;
    final String levelLowerCase = level.toLowerCase();
    if (levelLowerCase== "fatal") return Level.FATAL;
    else if (levelLowerCase == "error") return Level.ERROR;
    else if (levelLowerCase == "warning") return Level.WARNING;
    else if (levelLowerCase == "info") return Level.INFO;
    else if (levelLowerCase == "debug") return Level.DEBUG;
    else return Level.FATAL;
  }

  @ReactMethod
  public final void capture(final ReadableMap event, final Promise promise) {
    final EventBuilder eb = new EventBuilder();
    eb.withMessage(event.getString("message"));
    eb.withLevel(getLevel(event.getString("level")));
    eb.withLogger(event.getString("class"));
    eb.withSentryInterface(new ExceptionInterface(new Exception(event.getString("stack"))));
    Raven.capture(eb.build());
    promise.resolve(null);
  }
}

@@ -814,454 +814,8 @@
  %7D%0A%0A
-  @Override%0A  public Map%3CString, Object%3E getConstants() %7B%0A    final Map%3CString, Object%3E constants = new HashMap%3C%3E();%0A    constants.put(%22SENTRY_EVENT_LEVEL_FATAL%22, Level.FATAL);%0A    constants.put(%22SENTRY_EVENT_LEVEL_ERROR%22, Level.ERROR);%0A    constants.put(%22SENTRY_EVENT_LEVEL_WARNING%22, Level.WARNING);%0A    constants.put(%22SENTRY_EVENT_LEVEL_INFO%22, Level.INFO);%0A    constants.put(%22SENTRY_EVENT_LEVEL_DEBUG%22, Level.DEBUG);%0A    return constants;%0A  %7D%0A%0A
   pr

remove constants