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

package com.hypixel.hytale.builtin.beds.sleep.systems.world;

import com.hypixel.hytale.server.core.asset.type.gameplay.SleepConfig;
import java.time.LocalDateTime;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.core.modules.time.WorldTimeResource;
import com.hypixel.hytale.server.core.universe.world.World;

public final class CanSleepInWorld
{
    public static Result check(final World world) {
        if (world.getWorldConfig().isGameTimePaused()) {
            return Status.GAME_TIME_PAUSED;
        }
        final Store<EntityStore> store = world.getEntityStore().getStore();
        final LocalDateTime worldTime = store.getResource(WorldTimeResource.getResourceType()).getGameDateTime();
        final SleepConfig sleepConfig = world.getGameplayConfig().getWorldConfig().getSleepConfig();
        if (!sleepConfig.isWithinSleepHoursRange(worldTime)) {
            return new NotDuringSleepHoursRange(worldTime, sleepConfig);
        }
        return Status.CAN_SLEEP;
    }
    
    record NotDuringSleepHoursRange(LocalDateTime worldTime, SleepConfig sleepConfig) implements Result {
        @Override
        public boolean isNegative() {
            return true;
        }
    }
    
    public enum Status implements Result
    {
        CAN_SLEEP, 
        GAME_TIME_PAUSED;
        
        @Override
        public boolean isNegative() {
            return this != Status.CAN_SLEEP;
        }
    }
    
    public sealed interface Result permits NotDuringSleepHoursRange, Status
    {
        boolean isNegative();
    }
}
