namespace ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests.Cluster;

/// <summary>
/// Single source of truth for the dev-cluster database credential used by the
/// Playwright E2E suite.
///
/// <para>
/// The connection string mirrors the Docker cluster's <c>scadabridge_app</c>
/// account from <c>docker/central-node-a/appsettings.Central.json</c>, with the
/// host pointed at the host-exposed port (<c>localhost:1433</c>). The
/// <c>SCADABRIDGE_PLAYWRIGHT_DB</c> environment variable lets CI override the
/// connection without recompiling.
/// </para>
/// </summary>
internal static class PlaywrightDbConnection
{
    private const string DefaultConnectionString =
        "Server=localhost,1433;Database=ScadaBridgeConfig;User Id=scadabridge_app;Password=ScadaBridge_Dev1#;TrustServerCertificate=true;Encrypt=false;Connect Timeout=5";

    private const string EnvVar = "SCADABRIDGE_PLAYWRIGHT_DB";

    /// <summary>
    /// Connection string for the running cluster's configuration DB. Resolved
    /// from <c>SCADABRIDGE_PLAYWRIGHT_DB</c> when set (non-whitespace), otherwise
    /// the local docker dev defaults.
    /// </summary>
    public static string ConnectionString
    {
        get
        {
            var fromEnv = Environment.GetEnvironmentVariable(EnvVar);
            return string.IsNullOrWhiteSpace(fromEnv) ? DefaultConnectionString : fromEnv;
        }
    }
}
