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

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

import javax.annotation.Nullable;
import java.util.Collection;
import com.hypixel.hytale.common.util.StringUtil;
import java.util.EnumSet;
import javax.annotation.Nonnull;
import java.util.function.Supplier;

public enum RoleDebugFlags implements Supplier<String>
{
    TraceFail("Trace failed steps"), 
    TraceSuccess("Trace matched steps"), 
    TraceSensorFailures("Trace failing sensors"), 
    Flock("Trace flock events"), 
    FlockDamage("Trace flock damage events"), 
    MotionControllerSteer("Trace steering activity of motion controllers"), 
    Collisions("Trace collision information of motion controllers"), 
    BlockCollisions("Trace collisions down to block level"), 
    ProbeBlockCollisions("Trace collisions down to block level when probing"), 
    MotionControllerMove("Trace movement activity of motion controllers"), 
    ValidatePositions("Validate computed movement positions are not intersecting blocks"), 
    SteeringRole("Debug blended steering behaviour from role like avoidance/separation"), 
    DisplayState("Set display name to contents of state"), 
    DisplayFlock("Set display name to flock state"), 
    DisplayTime("Set display name to day time"), 
    DisplayTarget("Set display name to locked target type"), 
    DisplayAnim("Display animation state"), 
    DisplayLightLevel("Display light levels"), 
    DisplayCustom("Display custom debug information (generated by debug components)"), 
    DisplayHP("Display NPC HP as numerical values"), 
    DisplayStamina("Display NPC Stamina as numerical values"), 
    Overlaps("Log overlapping blocks when validating position"), 
    Pathfinder("Display pathfinder status"), 
    DisplaySpeed("Display speed of entity"), 
    DisplayFreeSlots("Display free inventory slots"), 
    DisplayInternalId("Display the internal server ID for this entity"), 
    DisplayName("Display the role name for this entity"), 
    ValidateMath("Validate (some) math computations in movement"), 
    VisAvoidance("Visualize avoidance vectors"), 
    VisSeparation("Visualize separation vector"), 
    BeaconMessages("Enable debugging of beacon message sending and receiving");
    
    private static final RoleDebugPreset[] presets;
    private final String description;
    
    private RoleDebugFlags(final String description) {
        this.description = description;
    }
    
    @Override
    public String get() {
        return this.description;
    }
    
    @Nonnull
    public static EnumSet<RoleDebugFlags> getFlags(@Nonnull final String[] args) {
        if (args.length == 0) {
            throw new IllegalArgumentException("Missing debug flags! " + getValidNameString());
        }
        final EnumSet<RoleDebugFlags> flags = EnumSet.noneOf(RoleDebugFlags.class);
        for (final String arg : args) {
            final RoleDebugFlags debugFlag = StringUtil.parseEnum(RoleDebugFlags.class.getEnumConstants(), arg, StringUtil.MatchType.CASE_INSENSITIVE);
            if (debugFlag != null) {
                flags.add(debugFlag);
            }
            else {
                final EnumSet<RoleDebugFlags> preset = findPreset(arg);
                if (preset == null) {
                    throw new IllegalArgumentException("Invalid flag/preset '" + arg + "'! " + getValidNameString());
                }
                flags.addAll((Collection<?>)preset);
            }
        }
        return flags;
    }
    
    @Nonnull
    public static StringBuilder getListOfFlags(@Nonnull final EnumSet<RoleDebugFlags> flags, @Nonnull final StringBuilder stringBuilder) {
        boolean comma = false;
        for (final RoleDebugFlags flag : values()) {
            if (flags.contains(flag)) {
                if (comma) {
                    stringBuilder.append(", ");
                }
                stringBuilder.append(flag);
                comma = true;
            }
        }
        return stringBuilder;
    }
    
    public static StringBuilder getListOfAllFlags(@Nonnull final StringBuilder stringBuilder) {
        return getListOfFlags(EnumSet.allOf(RoleDebugFlags.class), stringBuilder);
    }
    
    public static StringBuilder getListOfAllPresets(@Nonnull final StringBuilder stringBuilder) {
        boolean comma = false;
        for (final RoleDebugPreset preset : RoleDebugFlags.presets) {
            if (comma) {
                stringBuilder.append(", ");
            }
            stringBuilder.append(preset.name);
            comma = true;
        }
        return stringBuilder;
    }
    
    @Nonnull
    public static EnumSet<RoleDebugFlags> getPreset(final String arg) {
        final EnumSet<RoleDebugFlags> preset = findPreset(arg);
        if (preset == null) {
            throw new IllegalArgumentException("Invalid flag/preset '" + arg + "'! " + getValidNameString());
        }
        final EnumSet<RoleDebugFlags> flags = EnumSet.noneOf(RoleDebugFlags.class);
        flags.addAll((Collection<?>)preset);
        return flags;
    }
    
    @Nonnull
    private static String getValidNameString() {
        final StringBuilder result = new StringBuilder();
        result.append("Valid presets are: ");
        boolean comma = false;
        for (final RoleDebugPreset preset : RoleDebugFlags.presets) {
            if (comma) {
                result.append(", ");
            }
            result.append(preset.name);
            comma = true;
        }
        result.append(". Valid flags are: ");
        getListOfFlags(EnumSet.allOf(RoleDebugFlags.class), result);
        return result.toString();
    }
    
    @Nullable
    private static EnumSet<RoleDebugFlags> findPreset(final String name) {
        for (final RoleDebugPreset preset : RoleDebugFlags.presets) {
            if (preset.name.equalsIgnoreCase(name)) {
                return preset.config;
            }
        }
        return null;
    }
    
    public static boolean havePreset(final String name) {
        for (final RoleDebugPreset preset : RoleDebugFlags.presets) {
            if (preset.name.equalsIgnoreCase(name)) {
                return true;
            }
        }
        return false;
    }
    
    static {
        presets = new RoleDebugPreset[] { new RoleDebugPreset("none", EnumSet.noneOf(RoleDebugFlags.class)), new RoleDebugPreset("all", EnumSet.allOf(RoleDebugFlags.class)), new RoleDebugPreset("move", EnumSet.of(RoleDebugFlags.MotionControllerMove, RoleDebugFlags.Collisions)), new RoleDebugPreset("steer", EnumSet.of(RoleDebugFlags.MotionControllerMove, RoleDebugFlags.MotionControllerSteer, RoleDebugFlags.Collisions)), new RoleDebugPreset("valid", EnumSet.of(RoleDebugFlags.MotionControllerMove, RoleDebugFlags.MotionControllerSteer, RoleDebugFlags.Collisions, RoleDebugFlags.ValidatePositions)), new RoleDebugPreset("block", EnumSet.of(RoleDebugFlags.MotionControllerMove, RoleDebugFlags.MotionControllerSteer, RoleDebugFlags.Collisions, RoleDebugFlags.BlockCollisions)), new RoleDebugPreset("visDist", EnumSet.of(RoleDebugFlags.VisAvoidance, RoleDebugFlags.VisSeparation)), new RoleDebugPreset("display", EnumSet.of(RoleDebugFlags.DisplayState, RoleDebugFlags.DisplayFlock, RoleDebugFlags.DisplayTime, RoleDebugFlags.DisplayTarget, RoleDebugFlags.DisplayAnim, RoleDebugFlags.DisplayLightLevel, RoleDebugFlags.DisplayCustom, RoleDebugFlags.DisplayHP, RoleDebugFlags.DisplayStamina, RoleDebugFlags.DisplaySpeed, RoleDebugFlags.DisplayFreeSlots, RoleDebugFlags.DisplayInternalId, RoleDebugFlags.DisplayName)), new RoleDebugPreset("default", EnumSet.complementOf((EnumSet<RoleDebugFlags>)EnumSet.of((E)RoleDebugFlags.ValidatePositions))) };
    }
    
    private static class RoleDebugPreset
    {
        public String name;
        public EnumSet<RoleDebugFlags> config;
        
        private RoleDebugPreset(final String name, final EnumSet<RoleDebugFlags> config) {
            this.name = name;
            this.config = config;
        }
    }
}
