package net.minecraft.commands.arguments;

import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.minecraft.network.chat.TranslatableComponent;
import com.mojang.brigadier.Message;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.SharedSuggestionProvider;
import java.util.function.Function;
import com.google.common.collect.Streams;
import com.mojang.brigadier.suggestion.Suggestions;
import java.util.concurrent.CompletableFuture;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import java.util.Collection;
import net.minecraft.world.level.dimension.DimensionType;
import com.mojang.brigadier.arguments.ArgumentType;

public class DimensionTypeArgument implements ArgumentType<DimensionType> {
    private static final Collection<String> EXAMPLES;
    public static final DynamicCommandExceptionType ERROR_INVALID_VALUE;
    
    public DimensionType parse(final StringReader stringReader) throws CommandSyntaxException {
        final ResourceLocation sm3 = ResourceLocation.read(stringReader);
        return Registry.DIMENSION_TYPE.getOptional(sm3).<Throwable>orElseThrow(() -> DimensionTypeArgument.ERROR_INVALID_VALUE.create(sm3));
    }
    
    public <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> commandContext, final SuggestionsBuilder suggestionsBuilder) {
        return SharedSuggestionProvider.suggestResource(Streams.<DimensionType>stream(DimensionType.getAllTypes()).<ResourceLocation>map(DimensionType::getName), suggestionsBuilder);
    }
    
    public Collection<String> getExamples() {
        return DimensionTypeArgument.EXAMPLES;
    }
    
    public static DimensionTypeArgument dimension() {
        return new DimensionTypeArgument();
    }
    
    public static DimensionType getDimension(final CommandContext<CommandSourceStack> commandContext, final String string) {
        return (DimensionType)commandContext.getArgument(string, (Class)DimensionType.class);
    }
    
    static {
        EXAMPLES = Stream.<DimensionType>of(new DimensionType[] { DimensionType.OVERWORLD, DimensionType.NETHER }).map(cbi -> DimensionType.getName(cbi).toString()).collect(Collectors.toList());
        final TranslatableComponent translatableComponent;
        ERROR_INVALID_VALUE = new DynamicCommandExceptionType(object -> {
            new TranslatableComponent("argument.dimension.invalid", new Object[] { object });
            return translatableComponent;
        });
    }
}
