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

import java.util.Optional;
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 DeltaFeatureConfiguration implements FeatureConfiguration {
    public static final Codec<DeltaFeatureConfiguration> CODEC;
    public final BlockState contents;
    public final BlockState rim;
    public final int minimumRadius;
    public final int maximumRadius;
    public final int maximumRimSize;
    
    public DeltaFeatureConfiguration(final BlockState cfj1, final BlockState cfj2, final int integer3, final int integer4, final int integer5) {
        this.contents = cfj1;
        this.rim = cfj2;
        this.minimumRadius = integer3;
        this.maximumRadius = integer4;
        this.maximumRimSize = integer5;
    }
    
    static {
        CODEC = RecordCodecBuilder.create(instance -> ((RecordCodecBuilder.Instance)instance).group((App)BlockState.CODEC.fieldOf("contents").forGetter(cno -> cno.contents), (App)BlockState.CODEC.fieldOf("rim").forGetter(cno -> cno.rim), (App)Codec.INT.fieldOf("minimum_radius").forGetter(cno -> cno.minimumRadius), (App)Codec.INT.fieldOf("maximum_radius").forGetter(cno -> cno.maximumRadius), (App)Codec.INT.fieldOf("maximum_rim").forGetter(cno -> cno.maximumRimSize)).apply(instance, DeltaFeatureConfiguration::new));
    }
    
    public static class Builder {
        Optional<BlockState> contents;
        Optional<BlockState> rim;
        int minRadius;
        int maxRadius;
        int maxRim;
        
        public Builder() {
            this.contents = Optional.<BlockState>empty();
            this.rim = Optional.<BlockState>empty();
        }
        
        public Builder radius(final int integer1, final int integer2) {
            this.minRadius = integer1;
            this.maxRadius = integer2;
            return this;
        }
        
        public Builder contents(final BlockState cfj) {
            this.contents = Optional.<BlockState>of(cfj);
            return this;
        }
        
        public Builder rim(final BlockState cfj, final int integer) {
            this.rim = Optional.<BlockState>of(cfj);
            this.maxRim = integer;
            return this;
        }
        
        public DeltaFeatureConfiguration build() {
            if (!this.contents.isPresent()) {
                throw new IllegalArgumentException("Missing contents");
            }
            if (!this.rim.isPresent()) {
                throw new IllegalArgumentException("Missing rim");
            }
            if (this.minRadius > this.maxRadius) {
                throw new IllegalArgumentException("Minimum radius cannot be greater than maximum radius");
            }
            return new DeltaFeatureConfiguration(this.contents.get(), this.rim.get(), this.minRadius, this.maxRadius, this.maxRim);
        }
    }
}
