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

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

import com.hypixel.hytale.server.core.util.message.MessageFormat;
import com.hypixel.hytale.server.core.Message;
import java.util.Objects;
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.OptionalArg;
import java.util.function.Consumer;
import java.util.function.BooleanSupplier;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractWorldCommand;

abstract class LightingSendToggleCommand extends AbstractWorldCommand
{
    @Nonnull
    private final String statusTranslationKey;
    @Nonnull
    private final BooleanSupplier getter;
    @Nonnull
    private final Consumer<Boolean> setter;
    @Nonnull
    private final OptionalArg<Boolean> enabledArg;
    
    protected LightingSendToggleCommand(@Nonnull final String name, @Nonnull final String description, @Nonnull final String enabledDesc, @Nonnull final String statusTranslationKey, @Nonnull final BooleanSupplier getter, @Nonnull final Consumer<Boolean> setter) {
        super(name, description);
        this.statusTranslationKey = statusTranslationKey;
        this.getter = getter;
        this.setter = setter;
        this.enabledArg = this.withOptionalArg("enabled", enabledDesc, ArgTypes.BOOLEAN);
    }
    
    @Override
    protected void execute(@Nonnull final CommandContext context, @Nonnull final World world, @Nonnull final Store<EntityStore> store) {
        final Boolean enabled = this.enabledArg.provided(context) ? this.enabledArg.get(context) : null;
        final Boolean newValue = Objects.requireNonNullElseGet(enabled, () -> !this.getter.getAsBoolean());
        this.setter.accept(newValue);
        context.sendMessage(Message.translation(this.statusTranslationKey).param("status", MessageFormat.enabled(newValue)));
    }
}
