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

package com.hypixel.hytale.server.core.command.commands.world.entity;

import org.bson.BsonDocument;
import com.hypixel.hytale.component.Holder;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.core.util.BsonUtil;
import java.util.logging.Level;
import com.hypixel.hytale.logger.HytaleLogger;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.arguments.types.EntityWrappedArg;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractWorldCommand;

public class EntityDumpCommand extends AbstractWorldCommand
{
    private static final Message MESSAGE_GENERAL_NO_ENTITY_IN_VIEW;
    private static final Message MESSAGE_COMMANDS_ENTITY_DUMP_DUMP_DONE;
    @Nonnull
    private final EntityWrappedArg entityArg;
    
    public EntityDumpCommand() {
        super("dump", "server.commands.entity.dump.desc");
        this.entityArg = this.withOptionalArg("entity", "server.commands.entity.dump.entity.desc", ArgTypes.ENTITY_ID);
    }
    
    @Override
    protected void execute(@Nonnull final CommandContext context, @Nonnull final World world, @Nonnull final Store<EntityStore> store) {
        final Ref<EntityStore> entityRef = this.entityArg.get(store, context);
        if (entityRef == null || !entityRef.isValid()) {
            context.sendMessage(EntityDumpCommand.MESSAGE_GENERAL_NO_ENTITY_IN_VIEW);
            return;
        }
        final Holder<EntityStore> holder = store.copyEntity(entityRef);
        final BsonDocument document = EntityStore.REGISTRY.serialize(holder);
        HytaleLogger.getLogger().at(Level.INFO).log("""
                                                    Entity: %s
                                                    %s
                                                    %s""", entityRef, holder, BsonUtil.toJson(document));
        context.sendMessage(EntityDumpCommand.MESSAGE_COMMANDS_ENTITY_DUMP_DUMP_DONE);
    }
    
    static {
        MESSAGE_GENERAL_NO_ENTITY_IN_VIEW = Message.translation("server.general.noEntityInView");
        MESSAGE_COMMANDS_ENTITY_DUMP_DUMP_DONE = Message.translation("server.commands.entity.dump.dumpDone");
    }
}
