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

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

import javax.annotation.Nonnull;
import java.nio.file.Path;
import com.hypixel.hytale.server.worldgen.prefab.PrefabCategory;

public class FileLoadingContext extends FileContext<FileLoadingContext>
{
    private final Registry<ZoneFileContext> zones;
    private final Registry<PrefabCategory> prefabCategories;
    private int zoneIdCounter;
    private int biomeIdCounter;
    
    public FileLoadingContext(@Nonnull final Path filepath) {
        super(-1, filepath.getFileName().toString(), filepath, null);
        this.zones = new Registry<ZoneFileContext>("Zone");
        this.prefabCategories = new Registry<PrefabCategory>("Category");
        this.zoneIdCounter = -1;
        this.biomeIdCounter = -1;
    }
    
    @Nonnull
    @Override
    public FileLoadingContext getParentContext() {
        return this;
    }
    
    @Nonnull
    public Registry<ZoneFileContext> getZones() {
        return this.zones;
    }
    
    @Nonnull
    public Registry<PrefabCategory> getPrefabCategories() {
        return this.prefabCategories;
    }
    
    @Nonnull
    protected ZoneFileContext createZone(final String name, final Path path) {
        return this.createZone(this.nextZoneId(), name, path);
    }
    
    @Nonnull
    protected ZoneFileContext createZone(final int id, final String name, final Path path) {
        return new ZoneFileContext(this.updateZoneId(id), name, path, this);
    }
    
    protected int nextZoneId() {
        return this.zoneIdCounter + 1;
    }
    
    protected int nextBiomeId() {
        return this.biomeIdCounter + 1;
    }
    
    protected int updateZoneId(final int id) {
        validateId(id, this.zoneIdCounter, "Zone");
        return this.zoneIdCounter = id;
    }
    
    protected int updateBiomeId(final int id) {
        validateId(id, this.biomeIdCounter, "Biome");
        return this.biomeIdCounter = id;
    }
    
    protected static void validateId(final int id, final int currentId, final String type) {
        if (id < 0 || id <= currentId) {
            throw new Error(String.format("Invalid ID '%s' registered for type %s. Current ID counter: %s", id, type, currentId));
        }
    }
    
    public interface Constants
    {
        public static final String ID_TYPE_ZONE = "Zone";
        public static final String ID_TYPE_BIOME = "Biome";
        public static final String ERROR_INVALID_ID = "Invalid ID '%s' registered for type %s. Current ID counter: %s";
    }
}
