package com.bugsnag.reactnative;

import com.bugsnag.android.BreadcrumbType;
import com.bugsnag.android.EndpointConfiguration;
import com.bugsnag.android.ErrorTypes;
import com.bugsnag.android.ImmutableConfig;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class ConfigSerializer implements WritableMapSerializer<ImmutableConfig> {

    @Override
    public void serialize(Map<String, Object> map, ImmutableConfig config) {
        map.put("apiKey", config.getApiKey());
        map.put("autoDetectErrors", config.getAutoDetectErrors());
        map.put("autoTrackSessions", config.getAutoTrackSessions());
        map.put("sendThreads", config.getSendThreads().toString());
        map.put("discardClasses", config.getDiscardClasses());
        map.put("projectPackages", config.getProjectPackages());
        map.put("enabledReleaseStages", config.getEnabledReleaseStages());
        map.put("releaseStage", config.getReleaseStage());
        map.put("buildUuid", config.getBuildUuid());
        map.put("appVersion", config.getAppVersion());
        map.put("versionCode", config.getVersionCode());
        map.put("codeBundleId", config.getCodeBundleId());
        map.put("type", config.getAppType());
        map.put("persistUser", config.getPersistUser());
        map.put("launchCrashThresholdMs", (int) config.getLaunchCrashThresholdMs());
        map.put("maxBreadcrumbs", config.getMaxBreadcrumbs());
        map.put("enabledBreadcrumbTypes", serializeBreadrumbTypes(config));
        map.put("enabledErrorTypes", serializeErrorTypes(config));
        map.put("endpoints", serializeEndpoints(config));
    }

    private Collection<String> serializeBreadrumbTypes(ImmutableConfig config) {
        Collection<String> crumbTypes = new HashSet<>();
        Set<BreadcrumbType> types = config.getEnabledBreadcrumbTypes();
        if (types != null) {
            for (BreadcrumbType type : types) {
                crumbTypes.add(type.toString());
            }
        }
        return crumbTypes;
    }

    private Map<String, Object> serializeErrorTypes(ImmutableConfig config) {
        Map<String, Object> map = new HashMap<>();
        ErrorTypes errorTypes = config.getEnabledErrorTypes();
        map.put("anrs", errorTypes.getAnrs());
        map.put("ndkCrashes", errorTypes.getNdkCrashes());
        map.put("unhandledExceptions", errorTypes.getUnhandledExceptions());
        return map;
    }

    private Map<String, Object> serializeEndpoints(ImmutableConfig config) {
        Map<String, Object> map = new HashMap<>();
        EndpointConfiguration endpoints = config.getEndpoints();
        map.put("notify", endpoints.getNotify());
        map.put("sessions", endpoints.getSessions());
        return map;
    }
}

@@ -1066,24 +1066,74 @@
 ildUuid());%0A
+        if (config.getAppVersion() != null) %7B%0A    
         map.
@@ -1171,24 +1171,34 @@
 Version());%0A
+        %7D%0A
         map.

Update packages/react-native/android/src/main/java/com/bugsnag/reactnative/ConfigSerializer.java