using System;
using Svrnty.CQRS.Events.Abstractions.Models;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Svrnty.CQRS.Events.Abstractions.Streaming;
///
/// Performs health checks on event streams and subscriptions.
///
public interface IStreamHealthCheck
{
///
/// Checks the health of a specific stream.
///
/// Name of the stream to check.
/// Cancellation token.
/// Health check result for the stream.
Task CheckStreamHealthAsync(string streamName, CancellationToken cancellationToken = default);
///
/// Checks the health of a specific subscription.
///
/// Name of the stream.
/// Name of the subscription to check.
/// Cancellation token.
/// Health check result for the subscription.
Task CheckSubscriptionHealthAsync(string streamName, string subscriptionName, CancellationToken cancellationToken = default);
///
/// Checks the health of all configured streams.
///
/// Cancellation token.
/// Dictionary of stream names to health check results.
Task> CheckAllStreamsAsync(CancellationToken cancellationToken = default);
///
/// Checks the health of all subscriptions across all streams.
///
/// Cancellation token.
/// Dictionary of subscription keys (streamName:subscriptionName) to health check results.
Task> CheckAllSubscriptionsAsync(CancellationToken cancellationToken = default);
}
///
/// Configuration for stream health checks.
///
public sealed class StreamHealthCheckOptions
{
///
/// Maximum consumer lag (in events) before marking as degraded.
/// Default: 1000 events.
///
public long DegradedConsumerLagThreshold { get; set; } = 1000;
///
/// Maximum consumer lag (in events) before marking as unhealthy.
/// Default: 10000 events.
///
public long UnhealthyConsumerLagThreshold { get; set; } = 10000;
///
/// Maximum time without progress before marking consumer as stalled (degraded).
/// Default: 5 minutes.
///
public TimeSpan DegradedStalledThreshold { get; set; } = TimeSpan.FromMinutes(5);
///
/// Maximum time without progress before marking consumer as stalled (unhealthy).
/// Default: 15 minutes.
///
public TimeSpan UnhealthyStalledThreshold { get; set; } = TimeSpan.FromMinutes(15);
///
/// Timeout for health check operations.
/// Default: 5 seconds.
///
public TimeSpan HealthCheckTimeout { get; set; } = TimeSpan.FromSeconds(5);
}