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

package com.hypixel.hytale.server.npc.corecomponents.builders;

import java.util.List;
import com.hypixel.hytale.server.npc.util.expression.Scope;
import com.hypixel.hytale.server.npc.validators.NPCLoadTimeValidationHelper;
import com.hypixel.hytale.server.npc.util.expression.ExecutionContext;
import com.hypixel.hytale.server.npc.asset.builder.BuilderDescriptorState;
import com.hypixel.hytale.server.npc.asset.builder.Builder;
import javax.annotation.Nonnull;
import com.google.gson.JsonElement;
import com.hypixel.hytale.server.npc.asset.builder.holder.BooleanHolder;
import com.hypixel.hytale.server.npc.instructions.Sensor;
import com.hypixel.hytale.server.npc.asset.builder.BuilderBase;

public abstract class BuilderSensorBase extends BuilderBase<Sensor>
{
    protected boolean once;
    protected final BooleanHolder enabled;
    
    public BuilderSensorBase() {
        this.enabled = new BooleanHolder();
    }
    
    @Nonnull
    @Override
    public Builder<Sensor> readCommonConfig(@Nonnull final JsonElement data) {
        super.readCommonConfig(data);
        this.getBoolean(data, "Once", aBoolean -> this.once = aBoolean, false, BuilderDescriptorState.Stable, "Sensor only triggers once", null);
        this.getBoolean(data, "Enabled", this.enabled, true, BuilderDescriptorState.Stable, "Whether this sensor should be enabled on the NPC", null);
        return this;
    }
    
    @Nonnull
    @Override
    public Class<Sensor> category() {
        return Sensor.class;
    }
    
    public boolean getOnce() {
        return this.once;
    }
    
    public void setOnce(final boolean once) {
        this.once = once;
    }
    
    @Override
    public boolean isEnabled(final ExecutionContext context) {
        return this.enabled.get(context);
    }
    
    @Override
    public boolean validate(final String configName, @Nonnull final NPCLoadTimeValidationHelper validationHelper, final ExecutionContext context, final Scope globalScope, @Nonnull final List<String> errors) {
        validationHelper.updateParentSensorOnce(this.once);
        return super.validate(configName, validationHelper, context, globalScope, errors);
    }
}
