using System.Collections.Generic;

namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Wonderware.Backend
{
    /// <summary>
    ///     Wonderware Historian SDK configuration. Populated from environment variables at
    ///     sidecar startup (see <c>Program.cs</c>): the supervisor (lmxopcua-side
    ///     <c>WonderwareHistorianClient</c>) spawns the sidecar with these env vars; UA
    ///     translation lives on the client side of the named-pipe IPC, so this surface is
    ///     kept OPC-UA-free. The legacy v1 Galaxy.Host / Proxy host this lived in retired
    ///     in PR 7.2.
    /// </summary>
    public sealed class HistorianConfiguration
    {
        /// <summary>Gets or sets a value indicating whether Historian integration is enabled.</summary>
        public bool Enabled { get; set; } = false;

        /// <summary>Single-node fallback when <see cref="ServerNames"/> is empty.</summary>
        public string ServerName { get; set; } = "localhost";

        /// <summary>
        ///     Ordered cluster nodes. When non-empty, the data source tries each in order on connect,
        ///     falling through to the next on failure. A failed node is placed in cooldown for
        ///     <see cref="FailureCooldownSeconds"/> before being re-eligible.
        /// </summary>
        public List<string> ServerNames { get; set; } = new();

        /// <summary>Gets or sets the failure cooldown period in seconds.</summary>
        public int FailureCooldownSeconds { get; set; } = 60;
        /// <summary>Gets or sets a value indicating whether to use integrated security.</summary>
        public bool IntegratedSecurity { get; set; } = true;
        /// <summary>Gets or sets the user name for authentication.</summary>
        public string? UserName { get; set; }
        /// <summary>Gets or sets the password for authentication.</summary>
        public string? Password { get; set; }
        /// <summary>Gets or sets the Historian server port.</summary>
        public int Port { get; set; } = 32568;
        /// <summary>Gets or sets the command timeout in seconds.</summary>
        public int CommandTimeoutSeconds { get; set; } = 30;
        /// <summary>Gets or sets the maximum number of values per read operation.</summary>
        public int MaxValuesPerRead { get; set; } = 10000;

        /// <summary>
        ///     Outer safety timeout applied to sync-over-async Historian operations. Must be
        ///     comfortably larger than <see cref="CommandTimeoutSeconds"/>.
        /// </summary>
        public int RequestTimeoutSeconds { get; set; } = 60;
    }
}
