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

package com.hypixel.hytale.server.npc.corecomponents.timer.builders;

import com.hypixel.hytale.server.npc.asset.builder.Builder;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import java.util.List;
import com.hypixel.hytale.server.npc.util.expression.Scope;
import com.hypixel.hytale.server.npc.util.expression.ExecutionContext;
import com.hypixel.hytale.server.npc.validators.NPCLoadTimeValidationHelper;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleArrayValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleSequenceValidator;
import com.google.gson.JsonElement;
import com.hypixel.hytale.server.npc.asset.builder.BuilderDescriptorState;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.npc.asset.builder.BuilderObjectReferenceHelper;
import com.hypixel.hytale.server.npc.asset.builder.holder.NumberArrayHolder;
import com.hypixel.hytale.server.npc.corecomponents.builders.BuilderMotionBase;
import com.hypixel.hytale.server.npc.instructions.Motion;

public abstract class BuilderMotionTimer<T extends Motion> extends BuilderMotionBase<T>
{
    public static final double[] DEFAULT_TIMER_RANGE;
    protected final NumberArrayHolder timerRange;
    protected BuilderObjectReferenceHelper<T> motion;
    
    public BuilderMotionTimer() {
        this.timerRange = new NumberArrayHolder();
    }
    
    @Nonnull
    @Override
    public String getShortDescription() {
        return "Execute a Motion for a specific maximum time";
    }
    
    @Nonnull
    @Override
    public String getLongDescription() {
        return "Execute a Motion for a specific maximum time. If the motion finishes earlier the Timer also finishes.";
    }
    
    @Nonnull
    @Override
    public BuilderDescriptorState getBuilderDescriptorState() {
        return BuilderDescriptorState.Stable;
    }
    
    @Nonnull
    @Override
    public BuilderMotionTimer<T> readConfig(@Nonnull final JsonElement data) {
        this.getDoubleRange(data, "Time", this.timerRange, BuilderMotionTimer.DEFAULT_TIMER_RANGE, DoubleSequenceValidator.betweenWeaklyMonotonic(0.0, Double.MAX_VALUE), BuilderDescriptorState.Stable, "Range of time from which the random timer length can be chosen", null);
        this.requireObject(data, "Motion", this.motion, BuilderDescriptorState.Stable, "Motion to execute", null, this.validationHelper);
        return this;
    }
    
    @Override
    public boolean validate(final String configName, @Nonnull final NPCLoadTimeValidationHelper validationHelper, @Nonnull final ExecutionContext context, final Scope globalScope, @Nonnull final List<String> errors) {
        return super.validate(configName, validationHelper, context, globalScope, errors) & this.motion.validate(configName, validationHelper, this.builderManager, context, globalScope, errors);
    }
    
    public double[] getTimerRange(@Nonnull final BuilderSupport support) {
        return this.timerRange.get(support.getExecutionContext());
    }
    
    @Nullable
    public T getMotion(@Nonnull final BuilderSupport builderSupport) {
        return this.motion.build(builderSupport);
    }
    
    static {
        DEFAULT_TIMER_RANGE = new double[] { 1.0, 1.0 };
    }
}
