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

package io.sentry.util;

import io.sentry.HubScopesWrapper;
import io.sentry.Sentry;
import io.sentry.HubAdapter;
import io.sentry.ScopesAdapter;
import io.sentry.Scopes;
import org.jetbrains.annotations.Nullable;
import io.sentry.IScopes;

public final class ScopesUtil
{
    public static void printScopesChain(@Nullable final IScopes scopes) {
        System.out.println("==========================================");
        System.out.println("=============== v Scopes v ===============");
        System.out.println("==========================================");
        printScopesChainInternal(scopes);
        System.out.println("==========================================");
        System.out.println("=============== ^ Scopes ^ ===============");
        System.out.println("==========================================");
    }
    
    private static void printScopesChainInternal(@Nullable final IScopes someScopes) {
        if (someScopes != null) {
            if (someScopes instanceof Scopes) {
                final Scopes scopes = (Scopes)someScopes;
                final String info = String.format("%-25s {g=%-25s, i=%-25s, c=%-25s} [%s]", scopes, scopes.getGlobalScope(), scopes.getIsolationScope(), scopes.getScope(), scopes.getCreator());
                System.out.println(info);
                printScopesChainInternal(someScopes.getParentScopes());
            }
            else if (someScopes instanceof ScopesAdapter || someScopes instanceof HubAdapter) {
                printScopesChainInternal(Sentry.getCurrentScopes());
            }
            else if (someScopes instanceof HubScopesWrapper) {
                final HubScopesWrapper wrapper = (HubScopesWrapper)someScopes;
                printScopesChainInternal(wrapper.getScopes());
            }
            else {
                System.out.println("Hit unhandled Scopes class" + someScopes.getClass());
            }
        }
        else {
            System.out.println("-");
        }
    }
}
