// 
// 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.server.core.universe.world.lighting.ChunkLightingManager;
import com.hypixel.hytale.server.core.universe.world.lighting.FullBrightLightCalculation;
import com.hypixel.hytale.server.core.universe.world.lighting.LightCalculation;
import com.hypixel.hytale.server.core.universe.world.lighting.FloodLightCalculation;
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.ArgumentType;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
import com.hypixel.hytale.server.core.command.system.arguments.system.FlagArg;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractWorldCommand;

public class LightingCalculationCommand extends AbstractWorldCommand
{
    @Nonnull
    private static final Message MESSAGE_COMMANDS_INVALIDATE_LIGHTING;
    @Nonnull
    private static final Message MESSAGE_COMMANDS_LIGHTING_CALCULATION_ALREADY_FULLBRIGHT;
    @Nonnull
    private final RequiredArg<LightCalculationType> calculationTypeArg;
    @Nonnull
    private final FlagArg invalidateFlag;
    
    public LightingCalculationCommand() {
        super("calculation", "server.commands.lightingcalculation.desc");
        this.calculationTypeArg = this.withRequiredArg("light-calculation", "server.commands.lightingcalculation.calculation.desc", ArgTypes.forEnum("server.commands.parsing.argtype.enum.name", LightCalculationType.class));
        this.invalidateFlag = this.withFlagArg("invalidate", "server.commands.lightingcalculation.invalidate.desc");
    }
    
    @Override
    protected void execute(@Nonnull final CommandContext context, @Nonnull final World world, @Nonnull final Store<EntityStore> store) {
        final LightCalculationType type = this.calculationTypeArg.get(context);
        final ChunkLightingManager chunkLighting = world.getChunkLighting();
        switch (type.ordinal()) {
            case 0: {
                chunkLighting.setLightCalculation(new FloodLightCalculation(chunkLighting));
                context.sendMessage(Message.translation("server.commands.lightingcalculation.setCalculation").param("calculation", "Flood"));
                break;
            }
            case 1: {
                final LightCalculation lightCalculation = chunkLighting.getLightCalculation();
                if (lightCalculation instanceof FullBrightLightCalculation) {
                    context.sendMessage(LightingCalculationCommand.MESSAGE_COMMANDS_LIGHTING_CALCULATION_ALREADY_FULLBRIGHT);
                    return;
                }
                chunkLighting.setLightCalculation(new FullBrightLightCalculation(chunkLighting, lightCalculation));
                context.sendMessage(Message.translation("server.commands.lightcalculation.setCalculationWithDelegate").param("delegate", lightCalculation.getClass().getSimpleName()));
                break;
            }
        }
        if (((Argument<Arg, Boolean>)this.invalidateFlag).get(context)) {
            chunkLighting.invalidateLoadedChunks();
            context.sendMessage(LightingCalculationCommand.MESSAGE_COMMANDS_INVALIDATE_LIGHTING);
        }
    }
    
    static {
        MESSAGE_COMMANDS_INVALIDATE_LIGHTING = Message.translation("server.commands.invalidatedlighting");
        MESSAGE_COMMANDS_LIGHTING_CALCULATION_ALREADY_FULLBRIGHT = Message.translation("server.commands.lightingcalculation.alreadyFullBright");
    }
    
    private enum LightCalculationType
    {
        FLOOD, 
        FULLBRIGHT;
    }
}
