// 
// 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 com.hypixel.hytale.server.npc.util.Timer;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleSingleValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleArrayValidator;
import com.hypixel.hytale.server.npc.asset.builder.BuilderDescriptorState;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleSequenceValidator;
import com.google.gson.JsonElement;
import com.hypixel.hytale.server.npc.corecomponents.timer.ActionTimer;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import com.hypixel.hytale.server.npc.asset.builder.holder.BooleanHolder;
import com.hypixel.hytale.server.npc.asset.builder.holder.DoubleHolder;
import com.hypixel.hytale.server.npc.asset.builder.holder.NumberArrayHolder;

public class BuilderActionTimerStart extends BuilderActionTimer
{
    protected final NumberArrayHolder startValueRange;
    protected final NumberArrayHolder restartValueRange;
    protected final DoubleHolder rate;
    protected final BooleanHolder repeating;
    
    public BuilderActionTimerStart() {
        this.startValueRange = new NumberArrayHolder();
        this.restartValueRange = new NumberArrayHolder();
        this.rate = new DoubleHolder();
        this.repeating = new BooleanHolder();
    }
    
    @Nonnull
    @Override
    public ActionTimer build(@Nonnull final BuilderSupport builderSupport) {
        return new ActionTimer(this, builderSupport);
    }
    
    @Nonnull
    @Override
    public String getShortDescription() {
        return "Start a timer";
    }
    
    @Nonnull
    @Override
    public String getLongDescription() {
        return "Start a timer";
    }
    
    @Nonnull
    @Override
    public BuilderActionTimer readConfig(@Nonnull final JsonElement data) {
        super.readConfig(data);
        this.requireDoubleRange(data, "StartValueRange", this.startValueRange, DoubleSequenceValidator.fromExclToInclWeaklyMonotonic(0.0, Double.MAX_VALUE), BuilderDescriptorState.Stable, "The range from which to pick an initial value to start at", null);
        this.requireDoubleRange(data, "RestartValueRange", this.restartValueRange, DoubleSequenceValidator.fromExclToInclWeaklyMonotonic(0.0, Double.MAX_VALUE), BuilderDescriptorState.Stable, "The range from which to pick a value when the timer is restarted", "The range from which to pick a value when the timer is restarted. The upper bound is also the timer max");
        this.getDouble(data, "Rate", this.rate, 1.0, DoubleSingleValidator.greater0(), BuilderDescriptorState.Stable, "The rate at which the timer will decrease", null);
        this.getBoolean(data, "Repeating", this.repeating, false, BuilderDescriptorState.Stable, "Whether to repeat the timer when countdown finishes", null);
        return this;
    }
    
    @Nonnull
    @Override
    public Timer.TimerAction getTimerAction() {
        return Timer.TimerAction.START;
    }
    
    public double[] getStartValueRange(@Nonnull final BuilderSupport builderSupport) {
        return this.startValueRange.get(builderSupport.getExecutionContext());
    }
    
    public double[] getRestartValueRange(@Nonnull final BuilderSupport builderSupport) {
        return this.restartValueRange.get(builderSupport.getExecutionContext());
    }
    
    public double getRate(@Nonnull final BuilderSupport builderSupport) {
        return this.rate.get(builderSupport.getExecutionContext());
    }
    
    public boolean isRepeating(@Nonnull final BuilderSupport support) {
        return this.repeating.get(support.getExecutionContext());
    }
}
