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

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

import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
import com.hypixel.hytale.server.core.modules.time.WorldTimeResource;
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.lifecycle.builders.BuilderSensorAge;
import java.time.Instant;
import com.hypixel.hytale.server.npc.corecomponents.SensorBase;

public class SensorAge extends SensorBase
{
    protected final Instant minAgeInstant;
    protected final Instant maxAgeInstant;
    
    public SensorAge(@Nonnull final BuilderSensorAge builderSensorAge, @Nonnull final BuilderSupport builderSupport) {
        super(builderSensorAge);
        final Instant[] ageRange = builderSensorAge.getAgeRange(builderSupport);
        this.minAgeInstant = ageRange[0];
        this.maxAgeInstant = ageRange[1];
    }
    
    @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;
        }
        final WorldTimeResource worldTimeResource = store.getResource(WorldTimeResource.getResourceType());
        final Instant currentInstant = worldTimeResource.getGameTime();
        return !currentInstant.isBefore(this.minAgeInstant) && !currentInstant.isAfter(this.maxAgeInstant);
    }
    
    @Override
    public InfoProvider getSensorInfo() {
        return null;
    }
}
