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

package com.hypixel.hytale.server.worldgen.prefab;

import java.util.Iterator;
import java.util.Map;
import java.util.function.BiConsumer;
import javax.annotation.Nullable;
import com.google.gson.JsonElement;

record PrefabCategory(String name, int priority) {
    public static final String FILENAME = "PrefabCategories.json";
    public static final int MIN_PRIORITY = Integer.MIN_VALUE;
    public static final int MAX_PRIORITY = Integer.MAX_VALUE;
    public static final PrefabCategory NONE;
    public static final PrefabCategory UNIQUE;
    
    public static void parse(@Nullable final JsonElement json, final BiConsumer<String, PrefabCategory> consumer) {
        if (json == null || !json.isJsonObject()) {
            return;
        }
        for (final Map.Entry<String, JsonElement> entry : json.getAsJsonObject().entrySet()) {
            final String name = entry.getKey();
            final JsonElement value = entry.getValue();
            if (!value.isJsonPrimitive() || !value.getAsJsonPrimitive().isNumber()) {
                throw new Error(String.format("Invalid prefab category priority for '%s'. Must be an integer", name));
            }
            consumer.accept(name, new PrefabCategory(name, value.getAsInt()));
        }
    }
    
    static {
        NONE = new PrefabCategory("None", Integer.MIN_VALUE);
        UNIQUE = new PrefabCategory("Unique", Integer.MAX_VALUE);
    }
}
