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

package io.sentry;

import java.lang.reflect.InvocationTargetException;
import io.sentry.util.Platform;
import org.jetbrains.annotations.NotNull;
import io.sentry.util.LoadClass;
import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
public final class ScopesStorageFactory
{
    private static final String OTEL_SCOPES_STORAGE = "io.sentry.opentelemetry.OtelContextScopesStorage";
    
    @NotNull
    public static IScopesStorage create(@NotNull final LoadClass loadClass, @NotNull final ILogger logger) {
        final IScopesStorage storage = createInternal(loadClass, logger);
        storage.init();
        return storage;
    }
    
    @NotNull
    private static IScopesStorage createInternal(@NotNull final LoadClass loadClass, @NotNull final ILogger logger) {
        if (Platform.isJvm() && loadClass.isClassAvailable("io.sentry.opentelemetry.OtelContextScopesStorage", logger)) {
            final Class<?> otelScopesStorageClazz = loadClass.loadClass("io.sentry.opentelemetry.OtelContextScopesStorage", logger);
            if (otelScopesStorageClazz != null) {
                try {
                    final Object otelScopesStorage = otelScopesStorageClazz.getDeclaredConstructor((Class<?>[])new Class[0]).newInstance(new Object[0]);
                    if (otelScopesStorage != null && otelScopesStorage instanceof IScopesStorage) {
                        return (IScopesStorage)otelScopesStorage;
                    }
                }
                catch (final InstantiationException ex) {}
                catch (final IllegalAccessException ex2) {}
                catch (final InvocationTargetException ex3) {}
                catch (final NoSuchMethodException ex4) {}
            }
        }
        return new DefaultScopesStorage();
    }
}
