using System.Text.RegularExpressions;

namespace Jiaowu.Api.Infrastructure.Observability;

public sealed partial class PerformanceReportingOptions
{
    public const string SectionName = "PerformanceReporting";

    public bool Enabled { get; set; }
    public string PrometheusBaseUrl { get; set; } = "";
    public string BearerToken { get; set; } = "";
    public string GrafanaBaseUrl { get; set; } = "";
    public int CacheSeconds { get; set; } = 30;
    public int TimeoutSeconds { get; set; } = 10;
    public string ServiceLabel { get; set; } = "service_name";
    public string RequestDurationMetric { get; set; } =
        "http_server_request_duration_seconds";
    public string DatabaseDurationMetric { get; set; } =
        "jiaowu_db_command_duration_milliseconds";
    public string SlowDatabaseMetric { get; set; } =
        "jiaowu_db_command_slow_total";
    public string FailedDatabaseMetric { get; set; } =
        "jiaowu_db_command_failed_total";

    public static bool IsMetricOrLabelName(string value) =>
        !string.IsNullOrWhiteSpace(value) &&
        PrometheusNamePattern().IsMatch(value);

    [GeneratedRegex("^[a-zA-Z_:][a-zA-Z0-9_:]*$")]
    private static partial Regex PrometheusNamePattern();
}
