using ZB.MOM.WW.GalaxyRepository;

namespace ZB.MOM.WW.MxGateway.IntegrationTests.Galaxy;

/// <summary>Fact attribute that skips tests unless live Galaxy Repository tests are explicitly enabled.</summary>
public sealed class LiveGalaxyRepositoryFactAttribute : FactAttribute
{
    /// <summary>Environment variable name to enable live Galaxy Repository tests.</summary>
    public const string EnableVariableName = "MXGATEWAY_RUN_LIVE_GALAXY_TESTS";
    /// <summary>Environment variable name for the Galaxy Repository connection string.</summary>
    public const string ConnectionStringVariableName = "MXGATEWAY_LIVE_GALAXY_CONN";

    /// <summary>Initializes a new instance of the LiveGalaxyRepositoryFactAttribute class.</summary>
    public LiveGalaxyRepositoryFactAttribute()
    {
        if (!Enabled)
        {
            Skip = $"Set {EnableVariableName}=1 to run live Galaxy Repository tests.";
        }
    }

    /// <summary>Gets a value indicating whether live Galaxy Repository tests are enabled.</summary>
    public static bool Enabled => IntegrationTestEnvironment.IsEnabled(EnableVariableName);

    /// <summary>
    ///     Gets the Galaxy Repository connection string from environment or the production
    ///     default. The default is sourced from <see cref="GalaxyRepositoryOptions.DefaultConnectionString"/>
    ///     so the live-test fallback cannot drift away from the production default.
    /// </summary>
    public static string ConnectionString =>
        Environment.GetEnvironmentVariable(ConnectionStringVariableName)
            ?? GalaxyRepositoryOptions.DefaultConnectionString;
}
