using System.Text.RegularExpressions;

namespace Jiaowu.Api.Infrastructure.Analytics;

public sealed partial class ClickHouseAnalyticsOptions
{
    public const string SectionName = "ClickHouseAnalytics";

    public bool Enabled { get; set; }
    public string Endpoint { get; set; } = "http://localhost:8123";
    public string Database { get; set; } = "jiaowu_analytics";
    public string UserName { get; set; } = "jiaowu_analytics";
    public string Password { get; set; } = "";
    public bool CreateSchemaOnStartup { get; set; } = true;
    public int SyncIntervalSeconds { get; set; } = 60;
    public int SourceLookbackDays { get; set; } = 90;
    public int BatchSize { get; set; } = 1000;

    [GeneratedRegex("^[a-zA-Z_][a-zA-Z0-9_]{0,62}$")]
    private static partial Regex IdentifierPattern();

    public bool HasValidIdentifiers() =>
        IdentifierPattern().IsMatch(Database);
}
