ElevatorDiag/Diagnostics.cs

44 lines
1.2 KiB
C#

namespace ElevatorDiag;
public record ElevatorHealth(
bool IsHealthy,
ElevatorState State,
int CurrentFloor,
double PrecisePosition,
string? ActiveFault,
int PendingRequestsCount
);
public class ElevatorDiagnostics
{
private readonly Elevator _elevator;
public ElevatorDiagnostics(Elevator elevator)
{
_elevator = elevator;
}
public ElevatorHealth GetHealth()
{
return new ElevatorHealth(
_elevator.State != ElevatorState.Faulted,
_elevator.State,
_elevator.CurrentFloor,
_elevator.CurrentPosition,
_elevator.LastFault,
_elevator.TargetFloors.Count
);
}
public string GetStatusReport()
{
var health = GetHealth();
return $"[Elevator Report]\n" +
$"Status: {(health.IsHealthy ? "OK" : "FAULTED")}\n" +
$"State: {health.State}\n" +
$"Floor: {health.CurrentFloor} ({health.PrecisePosition:F2})\n" +
$"Pending: {health.PendingRequestsCount} floors\n" +
(health.ActiveFault != null ? $"Fault Detail: {health.ActiveFault}\n" : "");
}
}