using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Nexus.Api.Services; namespace Nexus.Api.Controllers; /// /// Health-check endpoint for the Gateway WebSocket connection. /// [ApiController] [AllowAnonymous] public class GatewayHealthController(IGatewayConnector connector) : ControllerBase { /// /// Returns the current Gateway WebSocket connection health. /// [HttpGet("/api/health/gateway")] public IResult GetGatewayHealth() { return Results.Ok(new { status = connector.ConnectionState.ToString().ToLowerInvariant(), connected = connector.ConnectionState == GatewayConnectionState.Connected, gatewayVersion = connector.GatewayVersion ?? "unknown", requiredVersion = connector.RequiredVersion, versionPinned = connector.RequiredVersion is not null, protocolVersion = connector.ProtocolVersion, advertisedMethodCount = connector.AdvertisedMethods.Count, lastConnectedAt = connector.LastConnectedAt?.ToString("o"), lastEventAt = connector.LastEventAt?.ToString("o"), reconnectAttempts = connector.ReconnectAttempts, message = connector.StatusMessage, timestamp = DateTimeOffset.UtcNow.ToString("o") }); } }