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

package com.hypixel.hytale.builtin.blockspawner;

import com.hypixel.hytale.codec.schema.metadata.Metadata;
import com.hypixel.hytale.codec.schema.metadata.ui.UIDefaultCollapsedState;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.common.map.IWeightedElement;
import com.hypixel.hytale.server.core.codec.WeightedMapCodec;
import com.hypixel.hytale.codec.Codec;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
import com.hypixel.hytale.codec.validation.ValidationResults;
import javax.annotation.Nonnull;
import com.hypixel.hytale.common.map.WeightedMap;
import javax.annotation.Nullable;
import com.hypixel.hytale.assetstore.AssetRegistry;
import com.hypixel.hytale.common.map.IWeightedMap;
import com.hypixel.hytale.assetstore.AssetExtraInfo;
import com.hypixel.hytale.assetstore.codec.AssetBuilderCodec;
import com.hypixel.hytale.assetstore.map.DefaultAssetMap;
import com.hypixel.hytale.assetstore.map.JsonAssetWithMap;

public class BlockSpawnerTable implements JsonAssetWithMap<String, DefaultAssetMap<String, BlockSpawnerTable>>
{
    public static final AssetBuilderCodec<String, BlockSpawnerTable> CODEC;
    private static DefaultAssetMap<String, BlockSpawnerTable> ASSET_MAP;
    protected AssetExtraInfo.Data data;
    protected String id;
    protected IWeightedMap<BlockSpawnerEntry> entries;
    
    public static DefaultAssetMap<String, BlockSpawnerTable> getAssetMap() {
        if (BlockSpawnerTable.ASSET_MAP == null) {
            BlockSpawnerTable.ASSET_MAP = AssetRegistry.getAssetStore(BlockSpawnerTable.class).getAssetMap();
        }
        return BlockSpawnerTable.ASSET_MAP;
    }
    
    public BlockSpawnerTable(final String id, @Nullable final IWeightedMap<BlockSpawnerEntry> entries) {
        this.id = id;
        this.entries = ((entries == null) ? WeightedMap.builder(BlockSpawnerEntry.EMPTY_ARRAY).build() : entries);
    }
    
    protected BlockSpawnerTable() {
    }
    
    @Override
    public String getId() {
        return this.id;
    }
    
    public IWeightedMap<BlockSpawnerEntry> getEntries() {
        return this.entries;
    }
    
    @Override
    public boolean equals(@Nullable final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        final BlockSpawnerTable table = (BlockSpawnerTable)o;
        if (this.id != null) {
            if (this.id.equals(table.id)) {
                return (this.entries != null) ? this.entries.equals(table.entries) : (table.entries == null);
            }
        }
        else if (table.id == null) {
            return (this.entries != null) ? this.entries.equals(table.entries) : (table.entries == null);
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        int result = (this.id != null) ? this.id.hashCode() : 0;
        result = 31 * result + ((this.entries != null) ? this.entries.hashCode() : 0);
        return result;
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "BlockSpawnerTable{id='" + this.id + "'}";
    }
    
    static {
        CODEC = AssetBuilderCodec.builder(BlockSpawnerTable.class, BlockSpawnerTable::new, (Codec<String>)Codec.STRING, (blockSpawnerTable, id) -> blockSpawnerTable.id = id, blockSpawnerTable -> blockSpawnerTable.id, (asset, data) -> asset.data = data, asset -> asset.data).appendInherited(new KeyedCodec<IWeightedMap>("Entries", (Codec<IWeightedMap>)new WeightedMapCodec((Codec<IWeightedElement>)BlockSpawnerEntry.CODEC, BlockSpawnerEntry.EMPTY_ARRAY)), (blockSpawnerTable, o) -> blockSpawnerTable.entries = o, blockSpawnerTable -> blockSpawnerTable.entries, (blockSpawnerTable, parent) -> blockSpawnerTable.entries = WeightedMap.builder(BlockSpawnerEntry.EMPTY_ARRAY).putAll(parent.entries).build()).metadata(UIDefaultCollapsedState.UNCOLLAPSED).add().validator((asset, results) -> {
            final BlockSpawnerEntry[] arr$ = asset.getEntries().internalKeys();
            for (int len$ = arr$.length, i$ = 0; i$ < len$; ++i$) {
                final BlockSpawnerEntry entry = arr$[i$];
                if (BlockType.getAssetMap().getIndex(entry.getBlockName()) == Integer.MIN_VALUE) {
                    results.fail("BlockName \"" + entry.getBlockName() + "\" does not exist in BlockSpawnerEntry");
                }
            }
        }).build();
    }
}
