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

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

import com.hypixel.hytale.server.npc.instructions.Sensor;
import com.hypixel.hytale.server.npc.asset.builder.Builder;
import com.google.gson.JsonElement;
import com.hypixel.hytale.server.npc.asset.builder.BuilderDescriptorState;
import com.hypixel.hytale.server.npc.corecomponents.statemachine.SensorState;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import com.hypixel.hytale.server.npc.corecomponents.builders.BuilderSensorBase;

public class BuilderSensorState extends BuilderSensorBase
{
    protected String state;
    protected String subState;
    protected int stateIndex;
    protected int subStateIndex;
    protected boolean defaultSubState;
    protected boolean ignoreMissingSetState;
    protected boolean componentLocal;
    
    @Nonnull
    @Override
    public SensorState build(@Nonnull final BuilderSupport builderSupport) {
        return new SensorState(this, builderSupport);
    }
    
    @Nonnull
    @Override
    public String getShortDescription() {
        return "Test for a specific state";
    }
    
    @Nonnull
    @Override
    public String getLongDescription() {
        return "Signal if NPC is set to specific state.";
    }
    
    @Nonnull
    @Override
    public BuilderDescriptorState getBuilderDescriptorState() {
        return BuilderDescriptorState.Stable;
    }
    
    @Nonnull
    @Override
    public Builder<Sensor> readConfig(@Nonnull final JsonElement data) {
        this.requireStateString(data, "State", true, (state, subState, isDefault) -> {
            this.state = state;
            this.subState = subState;
            this.defaultSubState = isDefault;
            return;
        }, BuilderDescriptorState.Stable, "State to compare to", null);
        this.getBoolean(data, "IgnoreMissingSetState", v -> this.ignoreMissingSetState = v, false, BuilderDescriptorState.Stable, "Override and ignore checks for matching setter action that sets this state", "Override and ignore checks for matching setter action that sets this state. Intended for use in cases such as the FlockState action which sets the state via another NPC");
        this.registerStateSensor(this.state, this.subState, this::setIndexes);
        if (this.ignoreMissingSetState) {
            this.registerStateSetter(this.state, this.subState, (m, v) -> {});
        }
        this.componentLocal = this.isComponent();
        return this;
    }
    
    public int getState() {
        return this.stateIndex;
    }
    
    public void setIndexes(final int main, final int sub) {
        this.stateIndex = main;
        this.subStateIndex = sub;
    }
    
    public boolean isDefaultSubState() {
        return this.defaultSubState;
    }
    
    public int getSubStateIndex() {
        return this.subStateIndex;
    }
    
    public boolean isComponentLocal() {
        return this.componentLocal;
    }
}
