using ZB.MOM.WW.Health;

namespace ZB.MOM.WW.Overview.Observability;

/// <summary>Registers the dashboard's own health checks.</summary>
public static class ObservabilityServiceCollectionExtensions
{
    /// <summary>Check name for the registry-loaded probe.</summary>
    public const string RegistryLoadedCheckName = "registry-loaded";

    /// <summary>Check name for the poll-cycle liveness probe.</summary>
    public const string PollCycleCheckName = "last-poll-cycle-completed";

    /// <summary>
    /// Adds the two readiness checks that make the dashboard's own <c>/health/ready</c> mean
    /// something: that it bound a registry, and that it is still polling it.
    /// </summary>
    /// <param name="services">The service collection.</param>
    /// <returns>The same collection, for chaining.</returns>
    /// <remarks>
    /// Both are tagged <see cref="ZbHealthTags.Ready"/> only. The dashboard is a single stateless
    /// process with no active/standby concept, so it registers nothing on the active tier — its own
    /// <c>/health/active</c> is deliberately an empty, always-200 report.
    /// </remarks>
    public static IServiceCollection AddOverviewHealthChecks(this IServiceCollection services)
    {
        ArgumentNullException.ThrowIfNull(services);

        services.AddHealthChecks()
            .AddTypeActivatedCheck<RegistryLoadedHealthCheck>(
                RegistryLoadedCheckName, failureStatus: null, tags: [ZbHealthTags.Ready])
            .AddTypeActivatedCheck<PollCycleHealthCheck>(
                PollCycleCheckName, failureStatus: null, tags: [ZbHealthTags.Ready]);

        return services;
    }
}
