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

package com.hypixel.hytale.server.core.command.commands.debug;

import java.util.Iterator;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.assetstore.AssetMap;
import com.hypixel.hytale.assetstore.AssetStore;
import com.hypixel.hytale.assetstore.map.JsonAssetWithMap;
import java.util.Map;
import com.hypixel.hytale.assetstore.AssetRegistry;
import java.util.concurrent.CompletableFuture;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractAsyncCommand;
import com.hypixel.hytale.server.core.command.system.AbstractCommand;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractCommandCollection;

public class AssetsCommand extends AbstractCommandCollection
{
    public AssetsCommand() {
        super("assets", "server.commands.assets.desc");
        this.addSubCommand(new AssetTagsCommand());
        this.addSubCommand(new AssetsDuplicatesCommand());
        this.addSubCommand(new AssetLongestAssetNameCommand());
    }
    
    public static class AssetLongestAssetNameCommand extends AbstractAsyncCommand
    {
        public AssetLongestAssetNameCommand() {
            super("longest", "");
        }
        
        @Nonnull
        @Override
        protected CompletableFuture<Void> executeAsync(@Nonnull final CommandContext context) {
            return CompletableFuture.runAsync(() -> {
                for (Map.Entry<Class<? extends JsonAssetWithMap>, AssetStore<?, ?, ?>> e : AssetRegistry.getStoreMap().entrySet()) {
                    String longestName = "";
                    for (final Object asset : e.getValue().getAssetMap().getAssetMap().keySet()) {
                        final String name = e.getValue().transformKey(asset).toString();
                        if (name.length() > longestName.length()) {
                            longestName = name;
                        }
                    }
                    context.sendMessage(Message.raw("Longest asset name for " + e.getKey().getSimpleName() + ": " + longestName + " (" + longestName.length() + " characters)"));
                }
            });
        }
    }
}
