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

import java.util.stream.Collectors;
import java.util.Arrays;
import java.util.function.Function;
import net.minecraft.world.level.block.state.predicate.BlockPredicate;
import net.minecraft.world.level.block.Blocks;
import java.util.function.Predicate;
import java.util.Map;
import net.minecraft.util.StringRepresentable;
import com.mojang.datafixers.kinds.Applicative;
import com.mojang.datafixers.kinds.App;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.world.level.block.state.BlockState;
import com.mojang.serialization.Codec;

public class OreConfiguration implements FeatureConfiguration {
    public static final Codec<OreConfiguration> CODEC;
    public final Predicates target;
    public final int size;
    public final BlockState state;
    
    public OreConfiguration(final Predicates a, final BlockState cfj, final int integer) {
        this.size = integer;
        this.state = cfj;
        this.target = a;
    }
    
    static {
        CODEC = RecordCodecBuilder.create(instance -> ((RecordCodecBuilder.Instance)instance).group((App)Predicates.CODEC.fieldOf("target").forGetter(coc -> coc.target), (App)BlockState.CODEC.fieldOf("state").forGetter(coc -> coc.state), (App)Codec.INT.fieldOf("size").withDefault(0).forGetter(coc -> coc.size)).apply(instance, OreConfiguration::new));
    }
    
    public enum Predicates implements StringRepresentable {
        NATURAL_STONE("natural_stone", cfj -> {
            if (cfj != null) {
                return cfj.is(Blocks.STONE) || cfj.is(Blocks.GRANITE) || cfj.is(Blocks.DIORITE) || cfj.is(Blocks.ANDESITE);
            }
            else {
                return false;
            }
        }), 
        NETHERRACK("netherrack", (Predicate<BlockState>)new BlockPredicate(Blocks.NETHERRACK)), 
        NETHER_ORE_REPLACEABLES("nether_ore_replaceables", cfj -> {
            if (cfj != null) {
                return cfj.is(Blocks.NETHERRACK) || cfj.is(Blocks.BASALT) || cfj.is(Blocks.BLACKSTONE);
            }
            else {
                return false;
            }
        });
        
        public static final Codec<Predicates> CODEC;
        private static final Map<String, Predicates> BY_NAME;
        private final String name;
        private final Predicate<BlockState> predicate;
        
        private Predicates(final String string3, final Predicate<BlockState> predicate) {
            this.name = string3;
            this.predicate = predicate;
        }
        
        public String getName() {
            return this.name;
        }
        
        public static Predicates byName(final String string) {
            return Predicates.BY_NAME.get(string);
        }
        
        public Predicate<BlockState> getPredicate() {
            return this.predicate;
        }
        
        @Override
        public String getSerializedName() {
            return this.name;
        }
        
        static {
            CODEC = StringRepresentable.<Predicates>fromEnum(Predicates::values, Predicates::byName);
            BY_NAME = Arrays.<Predicates>stream(values()).collect(Collectors.toMap(Predicates::getName, a -> a));
        }
    }
}
