// 
// Decompiled by Procyon v0.6.0
// 

package io.sentry.config;

import java.util.Iterator;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Map;
import org.jetbrains.annotations.Nullable;
import io.sentry.util.StringUtils;
import org.jetbrains.annotations.NotNull;

final class EnvironmentVariablePropertiesProvider implements PropertiesProvider
{
    private static final String PREFIX = "SENTRY";
    
    @Nullable
    @Override
    public String getProperty(@NotNull final String property) {
        return StringUtils.removeSurrounding(System.getenv(this.propertyToEnvironmentVariableName(property)), "\"");
    }
    
    @NotNull
    @Override
    public Map<String, String> getMap(@NotNull final String property) {
        final String prefix = this.propertyToEnvironmentVariableName(property) + "_";
        final Map<String, String> result = new ConcurrentHashMap<String, String>();
        for (final Map.Entry<String, String> entry : System.getenv().entrySet()) {
            final String key = entry.getKey();
            if (key.startsWith(prefix)) {
                final String value = StringUtils.removeSurrounding(entry.getValue(), "\"");
                if (value == null) {
                    continue;
                }
                result.put(key.substring(prefix.length()).toLowerCase(Locale.ROOT), value);
            }
        }
        return result;
    }
    
    @NotNull
    private String propertyToEnvironmentVariableName(@NotNull final String property) {
        return "SENTRY_" + property.replace(".", "_").replace("-", "_").toUpperCase(Locale.ROOT);
    }
}
