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

package com.hypixel.hytale.server.worldgen.loader.climate;

import javax.annotation.Nonnull;
import com.google.gson.JsonObject;
import javax.annotation.Nullable;
import com.google.gson.JsonElement;
import java.nio.file.Path;
import com.hypixel.hytale.procedurallib.json.SeedString;
import com.hypixel.hytale.server.worldgen.climate.ClimateSearch;
import com.hypixel.hytale.procedurallib.json.JsonLoader;
import com.hypixel.hytale.procedurallib.json.SeedResource;

public class ClimateRuleJsonLoader<K extends SeedResource> extends JsonLoader<K, ClimateSearch.Rule>
{
    public ClimateRuleJsonLoader(final SeedString<K> seed, final Path dataFolder, @Nullable final JsonElement json) {
        super(seed, dataFolder, json);
    }
    
    @Nullable
    @Override
    public ClimateSearch.Rule load() {
        return new ClimateSearch.Rule(this.loadRange("Continent"), this.loadRange("Temperature"), this.loadRange("Intensity"), this.loadRange("Fade"));
    }
    
    protected ClimateSearch.Range loadRange(final String key) {
        if (this.has(key)) {
            final JsonObject json = this.mustGetObject(key, null);
            final double target = loadTarget(json);
            final double radius = loadRadius(json);
            final double weight = loadWeight(json);
            return new ClimateSearch.Range(target, radius, weight);
        }
        return ClimateSearch.Range.DEFAULT;
    }
    
    protected static double loadTarget(@Nonnull final JsonObject json) {
        return JsonLoader.mustGet("Target", json.get("Target"), null, Double.class, x$0 -> JsonLoader.isNumber(x$0), JsonElement::getAsDouble);
    }
    
    protected static double loadRadius(@Nonnull final JsonObject json) {
        return JsonLoader.mustGet("Radius", json.get("Radius"), null, Double.class, x$0 -> JsonLoader.isNumber(x$0), JsonElement::getAsDouble);
    }
    
    protected static double loadWeight(@Nonnull final JsonObject json) {
        return JsonLoader.mustGet("Weight", json.get("Weight"), null, Double.class, x$0 -> JsonLoader.isNumber(x$0), JsonElement::getAsDouble);
    }
    
    protected interface Constants
    {
        public static final String KEY_TARGET = "Target";
        public static final String KEY_RADIUS = "Radius";
        public static final String KEY_WEIGHT = "Weight";
    }
}
