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

package com.google.common.flogger.backend;

import com.google.common.flogger.LogSite;
import com.google.common.flogger.AbstractLogger;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.TimeUnit;
import com.google.common.flogger.context.Tags;
import java.util.logging.Level;
import com.google.common.flogger.context.ContextDataProvider;

public abstract class Platform
{
    private static String DEFAULT_PLATFORM;
    private static final String[] AVAILABLE_PLATFORMS;
    
    public static LogCallerFinder getCallerFinder() {
        return LazyHolder.INSTANCE.getCallerFinderImpl();
    }
    
    protected abstract LogCallerFinder getCallerFinderImpl();
    
    public static LoggerBackend getBackend(final String className) {
        return LazyHolder.INSTANCE.getBackendImpl(className);
    }
    
    protected abstract LoggerBackend getBackendImpl(final String p0);
    
    public static ContextDataProvider getContextDataProvider() {
        return LazyHolder.INSTANCE.getContextDataProviderImpl();
    }
    
    protected ContextDataProvider getContextDataProviderImpl() {
        return NoOpContextDataProvider.getInstance();
    }
    
    public static boolean shouldForceLogging(final String loggerName, final Level level, final boolean isEnabled) {
        return getContextDataProvider().shouldForceLogging(loggerName, level, isEnabled);
    }
    
    public static Tags getInjectedTags() {
        return getContextDataProvider().getTags();
    }
    
    public static Metadata getInjectedMetadata() {
        return getContextDataProvider().getMetadata();
    }
    
    public static long getCurrentTimeNanos() {
        return LazyHolder.INSTANCE.getCurrentTimeNanosImpl();
    }
    
    protected long getCurrentTimeNanosImpl() {
        return TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis());
    }
    
    public static String getConfigInfo() {
        return LazyHolder.INSTANCE.getConfigInfoImpl();
    }
    
    protected abstract String getConfigInfoImpl();
    
    static {
        Platform.DEFAULT_PLATFORM = "com.google.common.flogger.backend.system.DefaultPlatform";
        AVAILABLE_PLATFORMS = new String[] { Platform.DEFAULT_PLATFORM };
    }
    
    private static final class LazyHolder
    {
        private static final Platform INSTANCE;
        
        private static Platform loadFirstAvailablePlatform(final String[] platformClass) {
            Platform platform = null;
            try {
                platform = PlatformProvider.getPlatform();
            }
            catch (final NoClassDefFoundError noClassDefFoundError) {}
            if (platform != null) {
                return platform;
            }
            final StringBuilder errorMessage = new StringBuilder();
            final int length = platformClass.length;
            int i = 0;
            while (i < length) {
                final String clazz = platformClass[i];
                try {
                    return (Platform)Class.forName(clazz).getConstructor((Class<?>[])new Class[0]).newInstance(new Object[0]);
                }
                catch (final Throwable e) {
                    if (e instanceof InvocationTargetException) {
                        e = e.getCause();
                    }
                    errorMessage.append('\n').append(clazz).append(": ").append(e);
                    ++i;
                    continue;
                }
                break;
            }
            throw new IllegalStateException(errorMessage.insert(0, "No logging platforms found:").toString());
        }
        
        static {
            INSTANCE = loadFirstAvailablePlatform(Platform.AVAILABLE_PLATFORMS);
        }
    }
    
    public abstract static class LogCallerFinder
    {
        public abstract String findLoggingClass(final Class<? extends AbstractLogger<?>> p0);
        
        public abstract LogSite findLogSite(final Class<?> p0, final int p1);
    }
}
