package net.minecraft.world.level.levelgen.feature.configurations;

import java.util.function.Function;
import java.util.Random;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import net.minecraft.resources.ResourceLocation;
import java.util.Map;
import java.util.List;
import com.mojang.serialization.Codec;

public class MultiJigsawConfiguration implements FeatureConfiguration {
    public static final Codec<MultiJigsawConfiguration> CODEC;
    private final List<JigsawConfiguration> configurations;
    
    public MultiJigsawConfiguration(final Map<String, Integer> map) {
        final JigsawConfiguration jigsawConfiguration;
        this(map.entrySet().stream().map(entry -> {
            new JigsawConfiguration(new ResourceLocation(entry.getKey()), (int)entry.getValue());
            return jigsawConfiguration;
        }).collect(Collectors.toList()));
    }
    
    private MultiJigsawConfiguration(final List<JigsawConfiguration> list) {
        this.configurations = list;
    }
    
    public JigsawConfiguration getRandomPool(final Random random) {
        return this.configurations.get(random.nextInt(this.configurations.size()));
    }
    
    static {
        CODEC = JigsawConfiguration.CODEC.listOf().xmap((Function)MultiJigsawConfiguration::new, cnx -> cnx.configurations);
    }
}
