using VigilCare.Simulation;

public sealed class RunStateReplayObserver : IReplayObserver
{
    private readonly SimulationRunState _state;

    public RunStateReplayObserver(SimulationRunState state) => _state = state;

    public void Header(string name, string? description) { }

    public void Info(string message) { }

    public void Event(string simTime, string description) =>
        _state.NoteEvent(description);

    public void Waiting(double deltaMinutes, int delayMs) { }

    public void Warn(string message) { }

    public void Error(string message) { }

    public void DryRun(string message) { }

    public void Completed(ReplayResult result) => SyncFromResult(result);

    public void Progress(double offsetMinutes, int clusterIndex, int clusterCount) =>
        _state.UpdateOffset(offsetMinutes);

    public void SyncFromResult(ReplayResult result)
    {
        _state.ApplyResultCounters(
            result.ObservationsSent,
            result.MedicationsSent,
            result.OrdersPlaced);
        _state.SetIds(
            result.PatientId == Guid.Empty ? null : result.PatientId,
            result.EncounterId == Guid.Empty ? null : result.EncounterId);
    }
}
