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

package com.hypixel.hytale.server.npc.asset.builder.holder;

import java.util.function.Supplier;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.npc.asset.builder.BuilderParameters;
import javax.annotation.Nonnull;
import com.google.gson.JsonElement;
import com.hypixel.hytale.server.npc.util.expression.ExecutionContext;
import com.hypixel.hytale.server.npc.asset.builder.expression.BuilderExpression;
import com.hypixel.hytale.server.npc.util.expression.ValueType;
import com.hypixel.hytale.logger.HytaleLogger;

public abstract class ValueHolder
{
    protected static final boolean LOG_VALUES = false;
    protected static final HytaleLogger LOGGER;
    protected ValueType valueType;
    protected String name;
    protected BuilderExpression expression;
    
    protected ValueHolder(final ValueType valueType) {
        this.valueType = valueType;
    }
    
    public abstract void validate(final ExecutionContext p0);
    
    protected void readJSON(@Nonnull final JsonElement requiredJsonElement, final String name, @Nonnull final BuilderParameters builderParameters) {
        this.name = name;
        this.expression = BuilderExpression.fromJSON(requiredJsonElement, builderParameters, this.valueType);
    }
    
    protected void readJSON(@Nullable final JsonElement optionalJsonElement, @Nonnull final Supplier<BuilderExpression> defaultValue, final String name, @Nonnull final BuilderParameters builderParameters) {
        this.name = name;
        this.expression = ((optionalJsonElement != null) ? BuilderExpression.fromJSON(optionalJsonElement, builderParameters, this.valueType) : defaultValue.get());
    }
    
    public String getName() {
        return this.name;
    }
    
    public void setName(final String name) {
        this.name = name;
    }
    
    public boolean isStatic() {
        return this.expression.isStatic();
    }
    
    public String getExpressionString() {
        return this.expression.getExpression();
    }
    
    static {
        LOGGER = HytaleLogger.get("BuilderManager");
    }
}
