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

package com.hypixel.hytale.assetstore.iterator;

import java.util.Iterator;
import com.hypixel.hytale.assetstore.AssetRegistry;
import com.hypixel.hytale.assetstore.JsonAsset;
import javax.annotation.Nonnull;
import com.hypixel.hytale.assetstore.AssetStore;
import java.util.Collection;

public class CircularDependencyException extends RuntimeException
{
    public CircularDependencyException(@Nonnull final Collection<AssetStore<?, ?, ?>> values, @Nonnull final AssetStoreIterator iterator) {
        super(makeMessage(values, iterator));
    }
    
    @Nonnull
    protected static String makeMessage(@Nonnull final Collection<AssetStore<?, ?, ?>> values, @Nonnull final AssetStoreIterator iterator) {
        final StringBuilder sb = new StringBuilder("Failed to process any stores there must be a circular dependency! " + String.valueOf(values) + ", " + iterator.size() + "\nWaiting for Asset Stores:\n");
        for (final AssetStore<?, ?, ?> store : values) {
            if (iterator.isWaitingForDependencies(store)) {
                sb.append(store.getAssetClass()).append("\n");
                for (final Class<? extends JsonAsset<?>> aClass : store.getLoadsAfter()) {
                    final AssetStore otherStore = AssetRegistry.getAssetStore(aClass);
                    if (otherStore == null) {
                        throw new IllegalArgumentException("Unable to find asset store: " + String.valueOf(aClass));
                    }
                    if (!iterator.isWaitingForDependencies(otherStore)) {
                        continue;
                    }
                    sb.append("\t- ").append(otherStore.getAssetClass()).append("\n");
                }
            }
        }
        return sb.toString();
    }
}
