// Copyright 2012-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Adapted from server/opts.go in the NATS server Go source.
using System.Net.Security;
using System.Security.Authentication;
using System.Text.Json.Serialization;
using System.Threading;
using ZB.MOM.NatsNet.Server.Auth;
namespace ZB.MOM.NatsNet.Server;
///
/// Server configuration options block.
/// Mirrors Options struct in opts.go.
///
public sealed partial class ServerOptions
{
// -------------------------------------------------------------------------
// General / Startup
// -------------------------------------------------------------------------
public string ConfigFile { get; set; } = string.Empty;
[JsonPropertyName("server_name")]
public string ServerName { get; set; } = string.Empty;
[JsonPropertyName("host")]
public string Host { get; set; } = string.Empty;
[JsonPropertyName("port")]
public int Port { get; set; }
public bool DontListen { get; set; }
[JsonPropertyName("client_advertise")]
public string ClientAdvertise { get; set; } = string.Empty;
public bool CheckConfig { get; set; }
[JsonPropertyName("pid_file")]
public string PidFile { get; set; } = string.Empty;
[JsonPropertyName("ports_file_dir")]
public string PortsFileDir { get; set; } = string.Empty;
// -------------------------------------------------------------------------
// Logging & Debugging
// -------------------------------------------------------------------------
[JsonPropertyName("trace")]
public bool Trace { get; set; }
[JsonPropertyName("debug")]
public bool Debug { get; set; }
public bool TraceVerbose { get; set; }
public bool TraceHeaders { get; set; }
public bool NoLog { get; set; }
public bool NoSigs { get; set; }
public bool Logtime { get; set; }
public bool LogtimeUtc { get; set; }
[JsonPropertyName("logfile")]
public string LogFile { get; set; } = string.Empty;
[JsonPropertyName("log_size_limit")]
public long LogSizeLimit { get; set; }
public long LogMaxFiles { get; set; }
public bool Syslog { get; set; }
public string RemoteSyslog { get; set; } = string.Empty;
public int ProfPort { get; set; }
public int ProfBlockRate { get; set; }
public int MaxTracedMsgLen { get; set; }
// -------------------------------------------------------------------------
// Networking & Limits
// -------------------------------------------------------------------------
[JsonPropertyName("max_connections")]
public int MaxConn { get; set; }
public int MaxSubs { get; set; }
public byte MaxSubTokens { get; set; }
public int MaxControlLine { get; set; }
[JsonPropertyName("max_payload")]
public int MaxPayload { get; set; }
[JsonPropertyName("max_pending")]
public long MaxPending { get; set; }
public bool NoFastProducerStall { get; set; }
public bool ProxyRequired { get; set; }
public bool ProxyProtocol { get; set; }
public int MaxClosedClients { get; set; }
// -------------------------------------------------------------------------
// Connectivity
// -------------------------------------------------------------------------
[JsonPropertyName("ping_interval")]
public TimeSpan PingInterval { get; set; }
[JsonPropertyName("ping_max")]
public int MaxPingsOut { get; set; }
[JsonPropertyName("write_deadline")]
public TimeSpan WriteDeadline { get; set; }
public WriteTimeoutPolicy WriteTimeout { get; set; }
[JsonPropertyName("lame_duck_duration")]
public TimeSpan LameDuckDuration { get; set; }
[JsonPropertyName("lame_duck_grace_period")]
public TimeSpan LameDuckGracePeriod { get; set; }
// -------------------------------------------------------------------------
// HTTP / Monitoring
// -------------------------------------------------------------------------
public string HttpHost { get; set; } = string.Empty;
[JsonPropertyName("http_port")]
public int HttpPort { get; set; }
[JsonPropertyName("http_base_path")]
public string HttpBasePath { get; set; } = string.Empty;
[JsonPropertyName("https_port")]
public int HttpsPort { get; set; }
// -------------------------------------------------------------------------
// Authentication & Authorization
// -------------------------------------------------------------------------
[JsonPropertyName("username")]
public string Username { get; set; } = string.Empty;
[JsonPropertyName("password")]
public string Password { get; set; } = string.Empty;
[JsonPropertyName("authorization")]
public string Authorization { get; set; } = string.Empty;
[JsonPropertyName("auth_timeout")]
public double AuthTimeout { get; set; }
[JsonPropertyName("no_auth_user")]
public string NoAuthUser { get; set; } = string.Empty;
public string DefaultSentinel { get; set; } = string.Empty;
[JsonPropertyName("system_account")]
public string SystemAccount { get; set; } = string.Empty;
public bool NoSystemAccount { get; set; }
/// Parsed account objects from config. Mirrors Go opts.Accounts.
[JsonPropertyName("accounts")]
public List Accounts { get; set; } = [];
public AuthCalloutOpts? AuthCallout { get; set; }
public bool AlwaysEnableNonce { get; set; }
public List? Users { get; set; }
public List? Nkeys { get; set; }
public List