// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.procedurallib.json;

import java.util.function.DoubleUnaryOperator;
import javax.annotation.Nonnull;
import com.google.gson.JsonElement;
import java.nio.file.Path;
import javax.annotation.Nullable;
import com.hypixel.hytale.procedurallib.property.NoiseProperty;
import com.hypixel.hytale.procedurallib.property.CurveNoiseProperty;

public class CurveNoisePropertyJsonLoader<K extends SeedResource> extends JsonLoader<K, CurveNoiseProperty>
{
    @Nullable
    protected final NoiseProperty noise;
    
    public CurveNoisePropertyJsonLoader(final SeedString<K> seed, final Path dataFolder, final JsonElement json, @Nullable final NoiseProperty noise) {
        super(seed, dataFolder, json);
        this.noise = noise;
    }
    
    @Nonnull
    @Override
    public CurveNoiseProperty load() {
        return new CurveNoiseProperty(this.loadNoise(), this.loadDCurve());
    }
    
    @Nullable
    protected NoiseProperty loadNoise() {
        final NoiseProperty noise = this.noise;
        if (noise != null) {
            return noise;
        }
        if (this.has("Noise")) {
            return new NoisePropertyJsonLoader(this.seed, this.dataFolder, this.get("Noise")).load();
        }
        throw new Error("Missing Noise entry!");
    }
    
    @Nonnull
    protected DoubleUnaryOperator loadDCurve() {
        final double a = this.loadValue("A", 2.0);
        final double b = this.loadValue("B", -2.0);
        return new CurveNoiseProperty.PowerCurve(a, b);
    }
    
    protected double loadValue(final String key, final double def) {
        double value = def;
        if (this.has(key)) {
            value = this.get(key).getAsDouble();
        }
        return value;
    }
    
    public interface Constants
    {
        public static final String KEY_NOISE = "Noise";
        public static final String KEY_CONST_A = "A";
        public static final String KEY_CONST_B = "B";
        public static final double DEFAULT_A = 2.0;
        public static final double DEFAULT_B = -2.0;
    }
}
