using System; using Svrnty.CQRS.Events.Abstractions.Models; using System.Collections.Generic; namespace Svrnty.CQRS.Events.Abstractions.Models; /// /// Status of a health check. /// public enum HealthStatus { /// /// The component is healthy. /// Healthy = 0, /// /// The component is degraded but still functional. /// Degraded = 1, /// /// The component is unhealthy. /// Unhealthy = 2 } /// /// Result of a health check operation. /// public sealed record HealthCheckResult { /// /// Overall health status. /// public required HealthStatus Status { get; init; } /// /// Optional description of the health status. /// public string? Description { get; init; } /// /// Exception that occurred during the health check, if any. /// public Exception? Exception { get; init; } /// /// Additional data about the health check. /// public IReadOnlyDictionary? Data { get; init; } /// /// Time taken to perform the health check. /// public TimeSpan Duration { get; init; } /// /// Creates a healthy result. /// public static HealthCheckResult Healthy(string? description = null, IReadOnlyDictionary? data = null, TimeSpan duration = default) => new() { Status = HealthStatus.Healthy, Description = description, Data = data, Duration = duration }; /// /// Creates a degraded result. /// public static HealthCheckResult Degraded(string? description = null, Exception? exception = null, IReadOnlyDictionary? data = null, TimeSpan duration = default) => new() { Status = HealthStatus.Degraded, Description = description, Exception = exception, Data = data, Duration = duration }; /// /// Creates an unhealthy result. /// public static HealthCheckResult Unhealthy(string? description = null, Exception? exception = null, IReadOnlyDictionary? data = null, TimeSpan duration = default) => new() { Status = HealthStatus.Unhealthy, Description = description, Exception = exception, Data = data, Duration = duration }; }