using Microsoft.AspNetCore.SignalR;

namespace ZB.MOM.WW.OtOpcUa.Admin.Hubs;

/// <summary>
///     Pushes sticky alerts (crash-loop circuit trips, failed applies, reservation-release
///     anomalies) to subscribed admin clients. Alerts don't auto-clear — the operator acks them
///     from the UI via <see cref="AcknowledgeAsync"/>.
/// </summary>
public sealed class AlertHub : Hub
{
    public const string AllAlertsGroup = "__alerts__";

    public override async Task OnConnectedAsync()
    {
        await Groups.AddToGroupAsync(Context.ConnectionId, AllAlertsGroup);
        await base.OnConnectedAsync();
    }

    /// <summary>Client-initiated ack. The server side of ack persistence is deferred — v2.1.</summary>
    public Task AcknowledgeAsync(string alertId) => Task.CompletedTask;
}

public sealed record AlertMessage(
    string AlertId,
    string Severity,
    string Title,
    string Detail,
    DateTime RaisedAtUtc,
    string? ClusterId,
    string? NodeId);
