public class WardGateway
{
    public Guid Id { get; private set; }
    public Guid SiteId { get; private set; }
    public string GatewayCode { get; private set; } = string.Empty;
    public string Department { get; private set; } = string.Empty;
    public GatewayStatus Status { get; private set; } = GatewayStatus.Offline;
    public int ReportedBufferDepth { get; private set; }
    public DateTimeOffset? LastHeartbeatAt { get; private set; }
    public DateTimeOffset? LastSyncAt { get; private set; }
    public DateTimeOffset CreatedAt { get; private set; }

    public ClinicalSite Site { get; private set; } = null!;

    private WardGateway() { }

    public WardGateway(Guid siteId, string gatewayCode, string department)
    {
        SiteId = siteId;
        GatewayCode = gatewayCode;
        Department = department;
        CreatedAt = DateTimeOffset.UtcNow;
    }

    public void RecordHeartbeat(GatewayStatus status, int bufferDepth, DateTimeOffset at)
    {
        Status = status;
        ReportedBufferDepth = bufferDepth;
        LastHeartbeatAt = at;
    }

    public void MarkSynced(DateTimeOffset at)
    {
        LastSyncAt = at;
        ReportedBufferDepth = 0;
        if (Status == GatewayStatus.Degraded)
            Status = GatewayStatus.Online;
    }

    public void MarkOffline()
    {
        Status = GatewayStatus.Offline;
    }
}