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

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

import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import com.hypixel.hytale.server.npc.asset.builder.Feature;
import com.hypixel.hytale.server.npc.asset.builder.validators.StringValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.StringNullOrNotEmptyValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleValidator;
import com.hypixel.hytale.server.npc.asset.builder.BuilderDescriptorState;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleSingleValidator;
import com.hypixel.hytale.server.npc.instructions.Sensor;
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.StringHolder;
import com.hypixel.hytale.server.npc.corecomponents.world.SensorEvent;
import com.hypixel.hytale.server.npc.asset.builder.holder.EnumHolder;
import com.hypixel.hytale.server.npc.asset.builder.holder.DoubleHolder;
import com.hypixel.hytale.server.npc.corecomponents.builders.BuilderSensorBase;

public abstract class BuilderSensorEvent extends BuilderSensorBase
{
    protected final DoubleHolder range;
    protected final EnumHolder<SensorEvent.EventSearchType> searchType;
    protected final StringHolder lockOnTargetSlot;
    
    public BuilderSensorEvent() {
        this.range = new DoubleHolder();
        this.searchType = new EnumHolder<SensorEvent.EventSearchType>();
        this.lockOnTargetSlot = new StringHolder();
    }
    
    @Nonnull
    @Override
    public Builder<Sensor> readConfig(@Nonnull final JsonElement data) {
        this.requireDouble(data, "Range", this.range, DoubleSingleValidator.greater0(), BuilderDescriptorState.Stable, "Max range to listen in", null);
        this.getEnum(data, "SearchType", this.searchType, SensorEvent.EventSearchType.class, SensorEvent.EventSearchType.PlayerOnly, BuilderDescriptorState.Stable, "Whether to listen for events triggered by players, npcs, or both in a certain order", null);
        this.getString(data, "TargetSlot", this.lockOnTargetSlot, null, StringNullOrNotEmptyValidator.get(), BuilderDescriptorState.Stable, "A target slot to place the target in. If omitted, no slot will be used", null);
        this.provideFeature(Feature.LiveEntity);
        return this;
    }
    
    public double getRange(@Nonnull final BuilderSupport support) {
        return this.range.get(support.getExecutionContext());
    }
    
    public SensorEvent.EventSearchType getEventSearchType(@Nonnull final BuilderSupport support) {
        return this.searchType.get(support.getExecutionContext());
    }
    
    public int getLockOnTargetSlot(@Nonnull final BuilderSupport support) {
        final String slot = this.lockOnTargetSlot.get(support.getExecutionContext());
        if (slot == null) {
            return Integer.MIN_VALUE;
        }
        return support.getTargetSlot(slot);
    }
}
