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

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

import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.npc.role.Role;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.npc.corecomponents.builders.BuilderSensorBase;
import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.npc.corecomponents.timer.builders.BuilderSensorTimer;
import com.hypixel.hytale.server.npc.util.Timer;
import com.hypixel.hytale.server.npc.corecomponents.SensorBase;

public class SensorTimer extends SensorBase
{
    protected final double minTimeRemaining;
    protected final double maxTimeRemaining;
    protected final Timer timer;
    protected final Timer.TimerState timerState;
    
    public SensorTimer(@Nonnull final BuilderSensorTimer builderSensorTimer, @Nonnull final BuilderSupport builderSupport) {
        super(builderSensorTimer);
        this.timer = builderSensorTimer.getTimer(builderSupport);
        final double[] timerThresholds = builderSensorTimer.getRemainingTimeRange(builderSupport);
        this.minTimeRemaining = timerThresholds[0];
        this.maxTimeRemaining = timerThresholds[1];
        this.timerState = builderSensorTimer.getTimerState();
    }
    
    @Override
    public boolean matches(@Nonnull final Ref<EntityStore> ref, @Nonnull final Role role, final double dt, @Nonnull final Store<EntityStore> store) {
        if (!super.matches(ref, role, dt, store)) {
            return false;
        }
        if (!this.timer.isInitialised()) {
            return (this.timerState == Timer.TimerState.ANY || this.timerState == Timer.TimerState.STOPPED) && this.isBetween(0.0);
        }
        return this.timer.isInState(this.timerState) && this.isBetween(this.timer.getValue());
    }
    
    @Override
    public InfoProvider getSensorInfo() {
        return null;
    }
    
    protected boolean isBetween(final double value) {
        return value >= this.minTimeRemaining && value <= this.maxTimeRemaining;
    }
}
