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

package com.hypixel.hytale.server.npc.role.support;

import java.util.Iterator;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.npc.role.builders.BuilderRole;
import com.hypixel.hytale.server.npc.instructions.Sensor;
import com.hypixel.hytale.server.npc.role.RoleDebugFlags;
import java.util.EnumSet;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.npc.role.RoleDebugDisplay;
import com.hypixel.hytale.server.npc.entities.NPCEntity;

public class DebugSupport
{
    protected final NPCEntity parent;
    @Nullable
    protected RoleDebugDisplay debugDisplay;
    protected boolean debugRoleSteering;
    protected boolean debugMotionSteering;
    protected EnumSet<RoleDebugFlags> debugFlags;
    @Nullable
    protected String displayCustomString;
    @Nullable
    protected String displayPathfinderString;
    protected boolean traceSuccess;
    protected boolean traceFail;
    protected boolean traceSensorFails;
    protected Sensor lastFailingSensor;
    
    public DebugSupport(final NPCEntity parent, @Nonnull final BuilderRole builder) {
        this.parent = parent;
        this.debugFlags = builder.getDebugFlags();
    }
    
    @Nullable
    public RoleDebugDisplay getDebugDisplay() {
        return this.debugDisplay;
    }
    
    public boolean isTraceSuccess() {
        return this.traceSuccess;
    }
    
    public boolean isTraceFail() {
        return this.traceFail;
    }
    
    public boolean isTraceSensorFails() {
        return this.traceSensorFails;
    }
    
    public void setLastFailingSensor(final Sensor sensor) {
        this.lastFailingSensor = sensor;
    }
    
    public Sensor getLastFailingSensor() {
        return this.lastFailingSensor;
    }
    
    public boolean isDebugRoleSteering() {
        return this.debugRoleSteering;
    }
    
    public boolean isDebugMotionSteering() {
        return this.debugMotionSteering;
    }
    
    public void setDisplayCustomString(final String displayCustomString) {
        this.displayCustomString = displayCustomString;
    }
    
    @Nullable
    public String pollDisplayCustomString() {
        final String ret = this.displayCustomString;
        this.displayCustomString = null;
        return ret;
    }
    
    public void setDisplayPathfinderString(final String displayPathfinderString) {
        this.displayPathfinderString = displayPathfinderString;
    }
    
    @Nullable
    public String pollDisplayPathfinderString() {
        final String ret = this.displayPathfinderString;
        this.displayPathfinderString = null;
        return ret;
    }
    
    public EnumSet<RoleDebugFlags> getDebugFlags() {
        return this.debugFlags;
    }
    
    public void setDebugFlags(final EnumSet<RoleDebugFlags> debugFlags) {
        this.debugFlags = debugFlags;
        this.activate();
    }
    
    public boolean isDebugFlagSet(final RoleDebugFlags flag) {
        return this.debugFlags.contains(flag);
    }
    
    public boolean isAnyDebugFlagSet(@Nonnull final EnumSet<RoleDebugFlags> flags) {
        for (final RoleDebugFlags d : flags) {
            if (this.debugFlags.contains(d)) {
                return true;
            }
        }
        return false;
    }
    
    public void activate() {
        this.debugRoleSteering = this.isDebugFlagSet(RoleDebugFlags.SteeringRole);
        this.debugMotionSteering = this.isDebugFlagSet(RoleDebugFlags.MotionControllerSteer);
        this.traceFail = this.isDebugFlagSet(RoleDebugFlags.TraceFail);
        this.traceSuccess = this.isDebugFlagSet(RoleDebugFlags.TraceSuccess);
        this.traceSensorFails = this.isDebugFlagSet(RoleDebugFlags.TraceSensorFailures);
        this.debugDisplay = RoleDebugDisplay.create(this.debugFlags);
    }
}
