package leigh.mud.engine;

public enum Direction {
    NORTH, EAST, SOUTH, WEST, UP, DOWN;

    public static Direction getDirection(String dir) {
        dir = dir.toUpperCase();

        try {
            return valueOf(dir);
        } catch (IllegalArgumentException e) {
            // Do nothing
        }

        return switch (dir) {
            case "N" -> NORTH;
            case "E" -> EAST;
            case "S" -> SOUTH;
            case "W" -> WEST;
            case "U" -> UP;
            case "D" -> DOWN;
            default -> null;
        };
    }

    /**
     * Return the opposite direction for the one provided.
     */
    public static Direction opposite(Direction d) {
        return switch (d) {
            case NORTH -> SOUTH;
            case EAST -> WEST;
            case SOUTH -> NORTH;
            case WEST -> EAST;
            case UP -> DOWN;
            case DOWN -> UP;
            default -> null;
        };
    }
}
