namespace ZB.MOM.WW.LmxProxy.Host.Configuration
{
    /// <summary>
    ///     Configuration settings for LmxProxy service
    /// </summary>
    public class LmxProxyConfiguration
    {
        /// <summary>
        ///     gRPC server port
        /// </summary>
        public int GrpcPort { get; set; } = 50051;

        /// <summary>
        ///     Subscription management settings
        /// </summary>
        public SubscriptionConfiguration Subscription { get; set; } = new();

        /// <summary>
        ///     Windows service recovery settings
        /// </summary>
        public ServiceRecoveryConfiguration ServiceRecovery { get; set; } = new();

        /// <summary>
        ///     API key configuration file path
        /// </summary>
        public string ApiKeyConfigFile { get; set; } = "apikeys.json";

        /// <summary>
        ///     MxAccess connection settings
        /// </summary>
        public ConnectionConfiguration Connection { get; set; } = new();

        /// <summary>
        ///     TLS/SSL configuration for secure gRPC communication
        /// </summary>
        public TlsConfiguration Tls { get; set; } = new();

        /// <summary>
        ///     Web server configuration for status display
        /// </summary>
        public WebServerConfiguration WebServer { get; set; } = new();
    }

    /// <summary>
    ///     Configuration for MxAccess connection monitoring and reconnection
    /// </summary>
    public class ConnectionConfiguration
    {
        /// <summary>
        ///     Interval in seconds between connection health checks
        /// </summary>
        public int MonitorIntervalSeconds { get; set; } = 5;

        /// <summary>
        ///     Timeout in seconds for initial connection attempts
        /// </summary>
        public int ConnectionTimeoutSeconds { get; set; } = 30;

        /// <summary>
        ///     Whether to automatically reconnect when connection is lost
        /// </summary>
        public bool AutoReconnect { get; set; } = true;

        /// <summary>
        ///     Timeout in seconds for read operations
        /// </summary>
        public int ReadTimeoutSeconds { get; set; } = 5;

        /// <summary>
        ///     Timeout in seconds for write operations
        /// </summary>
        public int WriteTimeoutSeconds { get; set; } = 5;

        /// <summary>
        ///     Maximum number of concurrent read/write operations allowed
        /// </summary>
        public int? MaxConcurrentOperations { get; set; } = 10;

        /// <summary>
        ///     Name of the node to connect to (optional)
        /// </summary>
        public string? NodeName { get; set; }

        /// <summary>
        ///     Name of the galaxy to connect to (optional)
        /// </summary>
        public string? GalaxyName { get; set; }
    }

    /// <summary>
    ///     Configuration for web server that displays status information
    /// </summary>
    public class WebServerConfiguration
    {
        /// <summary>
        ///     Whether the web server is enabled
        /// </summary>
        public bool Enabled { get; set; } = true;

        /// <summary>
        ///     Port number for the web server
        /// </summary>
        public int Port { get; set; } = 8080;

        /// <summary>
        ///     Prefix URL for the web server (default: http://+:{Port}/)
        /// </summary>
        public string? Prefix { get; set; }
    }
}
