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

package com.hypixel.hytale.server.npc.valuestore;

import java.util.function.Supplier;
import com.hypixel.hytale.server.npc.asset.builder.SlotMapper;
import java.util.Arrays;
import com.hypixel.hytale.server.npc.NPCPlugin;
import com.hypixel.hytale.component.ComponentType;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Component;

public class ValueStore implements Component<EntityStore>
{
    @Nonnull
    private final String[] stringValues;
    @Nonnull
    private final int[] intValues;
    @Nonnull
    private final double[] doubleValues;
    
    public static ComponentType<EntityStore, ValueStore> getComponentType() {
        return NPCPlugin.get().getValueStoreComponentType();
    }
    
    private ValueStore(final int stringCount, final int intCount, final int doubleCount) {
        this.stringValues = new String[stringCount];
        this.intValues = new int[intCount];
        this.doubleValues = new double[doubleCount];
        Arrays.fill(this.intValues, Integer.MIN_VALUE);
        Arrays.fill(this.doubleValues, -1.7976931348623157E308);
    }
    
    public String readString(final int slot) {
        return this.stringValues[slot];
    }
    
    public void storeString(final int slot, final String value) {
        this.stringValues[slot] = value;
    }
    
    public int readInt(final int slot) {
        return this.intValues[slot];
    }
    
    public void storeInt(final int slot, final int value) {
        this.intValues[slot] = value;
    }
    
    public double readDouble(final int slot) {
        return this.doubleValues[slot];
    }
    
    public void storeDouble(final int slot, final double value) {
        this.doubleValues[slot] = value;
    }
    
    @Nonnull
    @Override
    public Component<EntityStore> clone() {
        return new ValueStore(this.stringValues.length, this.intValues.length, this.doubleValues.length);
    }
    
    public static class Builder
    {
        private final SlotMapper stringSlots;
        private final SlotMapper intSlots;
        private final SlotMapper doubleSlots;
        
        public Builder() {
            this.stringSlots = new SlotMapper();
            this.intSlots = new SlotMapper();
            this.doubleSlots = new SlotMapper();
        }
        
        public int getStringSlot(final String name) {
            return this.stringSlots.getSlot(name);
        }
        
        public int getIntSlot(final String name) {
            return this.intSlots.getSlot(name);
        }
        
        public int getDoubleSlot(final String name) {
            return this.doubleSlots.getSlot(name);
        }
        
        @Nonnull
        public ValueStore build() {
            return new ValueStore(this.stringSlots.slotCount(), this.intSlots.slotCount(), this.doubleSlots.slotCount());
        }
    }
    
    public enum Type implements Supplier<String>
    {
        String("String value"), 
        Int("Integer value"), 
        Double("Double value");
        
        public static final Type[] VALUES;
        private final String description;
        
        private Type(final String description) {
            this.description = description;
        }
        
        @Override
        public String get() {
            return this.description;
        }
        
        static {
            VALUES = values();
        }
    }
}
