namespace ReactorMaintenance.Simulation;

internal static class RobotSafetySystem
{
    public static LevelState Resolve(LevelState level)
    {
        var surface = level.GetSurface(level.Robot.Position);
        var unsafeElement = surface.Fuel >= Balancing.Current.RobotFuelSafetyThreshold || surface.Coolant >= Balancing.Current.RobotCoolantSafetyThreshold || surface.Electricity >= Balancing.Current.RobotElectricitySafetyThreshold;
        var unsafeHeat = surface.Heat >= Balancing.Current.RobotHeatSafetyThreshold && level.Robot.HeatImmunitySteps <= 0;
        return unsafeElement || unsafeHeat
            ? level with { Global = level.Global with { LevelState = ELevelState.Lost, TerminalLoss = true, Status = "ROBOT LOST" } }
            : level;
    }
}