using Microsoft.AspNetCore.SignalR; using WiBLL.Common; namespace WiSL.EndPoints.Hubs; // Concrete implementation of the BLL-defined IWiHubNotifier, wrapping // IHubContext — this is the one place in this module allowed to know about // SignalR, per CLAUDE.md's "BLL must never reference ASP.NET types" rule. Registered as a // Singleton in WiModule.cs (IHubContext itself is singleton and thread-safe). public class WiHubNotifier(IHubContext hubContext, ILogger logger) : IWiHubNotifier { public async Task NotifyExecutionChangedAsync(int workStationId, int wiExecutionId, byte execStatus, CancellationToken ct = default) { try { await hubContext.Clients.Group(WiHub.WorkstationGroup(workStationId)) .ReceiveExecutionStatusChanged(workStationId, wiExecutionId, execStatus); } catch (Exception ex) { logger.LogWarning(ex, "WiHubNotifier: failed to push execution change for WorkStationId {WorkStationId}", workStationId); } } public async Task NotifyStaffingChangedAsync(int productionLineId, DateOnly shiftDate, int shiftId, CancellationToken ct = default) { try { await hubContext.Clients.Group(WiHub.LineGroup(productionLineId)) .ReceiveStaffingChanged(productionLineId, shiftDate, shiftId); } catch (Exception ex) { logger.LogWarning(ex, "WiHubNotifier: failed to push staffing change for ProductionLineId {ProductionLineId}", productionLineId); } } public async Task NotifyAllocationChangedAsync(int productionLineId, DateOnly shiftDate, int shiftId, CancellationToken ct = default) { try { await hubContext.Clients.Group(WiHub.LineGroup(productionLineId)) .ReceiveAllocationChanged(productionLineId, shiftDate, shiftId); } catch (Exception ex) { logger.LogWarning(ex, "WiHubNotifier: failed to push allocation change for ProductionLineId {ProductionLineId}", productionLineId); } } public async Task NotifyWorkstationOutageChangedAsync(int productionLineId, int workStationId, CancellationToken ct = default) { try { await hubContext.Clients.Group(WiHub.LineGroup(productionLineId)) .ReceiveWorkstationOutageChanged(workStationId); } catch (Exception ex) { logger.LogWarning(ex, "WiHubNotifier: failed to push outage change for WorkStationId {WorkStationId}", workStationId); } } }