using Evergreen.Health.Application.Health.Sleep; namespace Evergreen.Health.Application.Health.Integrations.Ib43; public sealed record Ib43SavedBed(string BindingId, string Side); public sealed record Ib43SavedReport(int MatchedCount, IReadOnlyList ActiveBeds); internal static class Ib43PresenceAdapter { public static void Publish(IBedPresenceSink sink, Ib43Binding device, Ib43Report report, IReadOnlyList beds, Guid connectionId, CancellationToken connectionToken) { if (sink == null || !report.Accepted || report.Issues.Count != 0) return; foreach (var bed in beds) { if (bed.Side is not ("left" or "right") || !report.Readings.TryGetValue(bed.Side + ".presence", out var presence) || presence.Source != "ibNew" || presence.Value is not (0 or 1)) continue; sink.Observe(new(bed.BindingId, device.ProductKey, device.SerialNumber, bed.Side == "left" ? BedSide.Left : BedSide.Right, device.Simulation, presence.Value == 0 ? BedPresence.Empty : BedPresence.Occupied, presence.ReceivedAt, connectionId), connectionToken); } } }