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

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

import com.hypixel.hytale.server.npc.asset.builder.Builder;
import com.hypixel.hytale.server.npc.asset.builder.InstructionType;
import com.google.gson.JsonElement;
import com.hypixel.hytale.server.npc.asset.builder.BuilderDescriptorState;
import com.hypixel.hytale.server.npc.corecomponents.statemachine.ActionState;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import com.hypixel.hytale.server.npc.corecomponents.builders.BuilderActionBase;

public class BuilderActionState extends BuilderActionBase
{
    protected String state;
    protected String subState;
    protected int stateIndex;
    protected int subStateIndex;
    protected boolean clearState;
    protected boolean componentLocal;
    
    @Nonnull
    @Override
    public ActionState build(@Nonnull final BuilderSupport builderSupport) {
        return new ActionState(this, builderSupport);
    }
    
    @Nonnull
    @Override
    public String getShortDescription() {
        return "Set state of NPC";
    }
    
    @Nonnull
    @Override
    public String getLongDescription() {
        return "Set state of NPC. The state can be queried with a sensor later on.";
    }
    
    @Nonnull
    @Override
    public BuilderDescriptorState getBuilderDescriptorState() {
        return BuilderDescriptorState.Stable;
    }
    
    @Nonnull
    @Override
    public BuilderActionState readConfig(@Nonnull final JsonElement data) {
        this.requireStateString(data, "State", true, (state, subState, isDefault) -> {
            this.state = state;
            this.subState = subState;
            return;
        }, BuilderDescriptorState.Stable, "State name to set", null);
        this.getBoolean(data, "ClearState", v -> this.clearState = v, true, BuilderDescriptorState.Stable, "Clear the state of things like set once flags on transition", null);
        this.componentLocal = this.isComponent();
        this.registerStateSetter(this.state, this.subState, (main, sub) -> {
            this.stateIndex = main;
            this.subStateIndex = sub;
            return;
        });
        this.requireInstructionType(InstructionType.StateChangeAllowedInstructions);
        return this;
    }
    
    public int getStateIndex() {
        return this.stateIndex;
    }
    
    public int getSubStateIndex() {
        return this.subStateIndex;
    }
    
    public boolean isClearState() {
        return this.clearState;
    }
    
    public boolean isComponentLocal() {
        return this.componentLocal;
    }
}
