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

/// <summary>
///     Connection settings for the AVEVA System Platform Galaxy Repository (ZB) database.
///     Bound to the <c>MxGateway:Galaxy</c> configuration section.
/// </summary>
public sealed class GalaxyRepositoryOptions
{
    public const string SectionName = "MxGateway:Galaxy";

    /// <summary>
    ///     Default SQL Server connection string for the Galaxy Repository database.
    ///     Single source of truth shared with the integration-test fallback so the
    ///     production default and the live-test default cannot drift.
    /// </summary>
    public const string DefaultConnectionString =
        "Server=localhost;Database=ZB;Integrated Security=True;TrustServerCertificate=True;Encrypt=False;";

    /// <summary>The SQL Server connection string for the Galaxy Repository database.</summary>
    public string ConnectionString { get; init; } = DefaultConnectionString;

    /// <summary>The timeout in seconds for SQL commands executed against the Galaxy Repository.</summary>
    public int CommandTimeoutSeconds { get; init; } = 60;

    /// <summary>
    ///     Interval (seconds) between background refreshes of the dashboard Galaxy summary
    ///     cache. SQL is hit at most once per interval regardless of dashboard render rate.
    /// </summary>
    public int DashboardRefreshIntervalSeconds { get; init; } = 30;

    /// <summary>Default on-disk path for the persisted Galaxy browse snapshot.</summary>
    public const string DefaultSnapshotCachePath =
        @"C:\ProgramData\MxGateway\galaxy-snapshot.json";

    /// <summary>
    ///     Whether the gateway persists the latest successful Galaxy browse dataset to
    ///     disk. When enabled, the cache reloads that snapshot at startup so clients can
    ///     still browse last-known data while the Galaxy database is unreachable.
    /// </summary>
    public bool PersistSnapshot { get; init; } = true;

    /// <summary>
    ///     File path for the persisted Galaxy browse snapshot. Ignored when
    ///     <see cref="PersistSnapshot"/> is <see langword="false"/>.
    /// </summary>
    public string SnapshotCachePath { get; init; } = DefaultSnapshotCachePath;
}
