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

package com.hypixel.hytale.server.core.command.commands.utility.lighting;

import com.hypixel.hytale.server.core.command.system.arguments.system.Argument;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.ArchetypeChunk;
import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection;
import com.hypixel.hytale.server.core.universe.world.lighting.ChunkLightingManager;
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
import com.hypixel.hytale.component.query.Query;
import com.hypixel.hytale.server.core.universe.world.chunk.BlockChunk;
import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
import java.util.concurrent.atomic.AtomicInteger;
import com.hypixel.hytale.server.core.Message;
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 javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.arguments.system.FlagArg;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractWorldCommand;

public class LightingInfoCommand extends AbstractWorldCommand
{
    @Nonnull
    private final FlagArg detailFlag;
    static final /* synthetic */ boolean $assertionsDisabled;
    
    public LightingInfoCommand() {
        super("info", "server.commands.lighting.info.desc");
        this.detailFlag = this.withFlagArg("detail", "server.commands.lighting.info.detail.desc");
    }
    
    @Override
    protected void execute(@Nonnull final CommandContext context, @Nonnull final World world, @Nonnull final Store<EntityStore> store) {
        final Store<ChunkStore> chunkStoreStore = world.getChunkStore().getStore();
        final ChunkLightingManager chunkLighting = world.getChunkLighting();
        context.sendMessage(Message.translation("server.commands.lighting.info.summary").param("queueSize", chunkLighting.getQueueSize()).param("lightCalculation", chunkLighting.getLightCalculation().getClass().getSimpleName()));
        if (((Argument<Arg, Boolean>)this.detailFlag).get(context)) {
            final AtomicInteger total = new AtomicInteger();
            final AtomicInteger localLightCount = new AtomicInteger();
            final AtomicInteger globalLightCount = new AtomicInteger();
            chunkStoreStore.forEachEntityParallel(WorldChunk.getComponentType(), (index, archetypeChunk, commandBuffer) -> {
                int hasLocalCount = 0;
                int hasGlobalCount = 0;
                final BlockChunk blockChunkComponent = archetypeChunk.getComponent(index, BlockChunk.getComponentType());
                if (!LightingInfoCommand.$assertionsDisabled && blockChunkComponent == null) {
                    throw new AssertionError();
                }
                else {
                    for (int y = 0; y < 10; ++y) {
                        final BlockSection section = blockChunkComponent.getSectionAtBlockY(y);
                        if (section.hasLocalLight()) {
                            ++hasLocalCount;
                        }
                        if (section.hasGlobalLight()) {
                            ++hasGlobalCount;
                        }
                    }
                    total.getAndAdd(10);
                    localLightCount.getAndAdd(hasLocalCount);
                    globalLightCount.getAndAdd(hasGlobalCount);
                    return;
                }
            });
            context.sendMessage(Message.translation("server.commands.lighting.info.chunkDetails").param("totalChunkSections", total.get()).param("chunksWithLocalLight", localLightCount.get()).param("chunksWithGlobalLight", globalLightCount.get()));
        }
    }
}
