using System.Text.Json.Serialization;

namespace NATS.Server.Monitoring;

/// <summary>
/// Structured health response shape for /healthz.
/// Go reference: monitor.go HealthStatus.
/// </summary>
public sealed class HealthStatus
{
    [JsonPropertyName("status")]
    public string Status { get; init; } = "ok";

    [JsonPropertyName("status_code")]
    public int StatusCode { get; init; } = 200;

    [JsonPropertyName("error")]
    public string? Error { get; init; }

    [JsonPropertyName("errors")]
    public HealthzError[] Errors { get; init; } = [];

    public static HealthStatus Ok() => new();
}

/// <summary>
/// Individual health check failure record.
/// Go reference: monitor.go HealthzError.
/// </summary>
public sealed class HealthzError
{
    [JsonPropertyName("type")]
    public HealthzErrorType Type { get; init; } = HealthzErrorType.Unknown;

    [JsonPropertyName("error")]
    public string Error { get; init; } = string.Empty;
}

/// <summary>
/// Health error classification.
/// Go reference: monitor.go HealthZErrorType.
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum HealthzErrorType
{
    Unknown,
    JetStream,
    Account,
    Cluster,
}
