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

package com.hypixel.hytale.procedurallib.json;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import java.nio.file.Path;
import javax.annotation.Nonnull;
import com.hypixel.hytale.procedurallib.condition.BasicHeightThresholdInterpreter;

public class BasicHeightThresholdInterpreterJsonLoader<K extends SeedResource> extends JsonLoader<K, BasicHeightThresholdInterpreter>
{
    protected final int length;
    
    public BasicHeightThresholdInterpreterJsonLoader(@Nonnull final SeedString<K> seed, final Path dataFolder, final JsonElement json, final int length) {
        super(seed.append(".BasicHeightThresholdInterpreter"), dataFolder, json);
        this.length = length;
    }
    
    @Nonnull
    @Override
    public BasicHeightThresholdInterpreter load() {
        return new BasicHeightThresholdInterpreter(this.loadPositions(), this.loadValues(), this.length);
    }
    
    protected int[] loadPositions() {
        if (!this.has("Positions")) {
            throw new IllegalStateException("Could not find position data in HeightThresholdInterpreter. Keyword: Positions");
        }
        final JsonArray terrainNoiseKeyPositionsJson = this.get("Positions").getAsJsonArray();
        final int[] positions = new int[terrainNoiseKeyPositionsJson.size()];
        for (int i = 0; i < positions.length; ++i) {
            positions[i] = terrainNoiseKeyPositionsJson.get(i).getAsInt();
        }
        return positions;
    }
    
    protected float[] loadValues() {
        if (!this.has("Values")) {
            throw new IllegalStateException("Could not find value data in HeightThresholdInterpreter. Keyword: Values");
        }
        final JsonArray terrainNoiseKeyThresholdsJson = this.get("Values").getAsJsonArray();
        final float[] thresholds = new float[terrainNoiseKeyThresholdsJson.size()];
        for (int i = 0; i < thresholds.length; ++i) {
            thresholds[i] = terrainNoiseKeyThresholdsJson.get(i).getAsFloat();
        }
        return thresholds;
    }
    
    public interface Constants
    {
        public static final String KEY_POSITIONS = "Positions";
        public static final String KEY_VALUES = "Values";
        public static final String ERROR_NO_POSITIONS = "Could not find position data in HeightThresholdInterpreter. Keyword: Positions";
        public static final String ERROR_NO_VALUES = "Could not find value data in HeightThresholdInterpreter. Keyword: Values";
    }
}
