namespace NATS.Server;
///
/// MQTT protocol configuration options.
/// Corresponds to Go server/opts.go MQTTOpts struct.
/// Config is parsed and stored but no MQTT listener is started yet.
///
public sealed class MqttOptions
{
// Network
/// Host interface for the MQTT listener.
public string Host { get; set; } = "";
/// Port for the MQTT listener.
public int Port { get; set; }
// Auth override (MQTT-specific, separate from global auth)
/// Default user to apply when MQTT clients connect without credentials.
public string? NoAuthUser { get; set; }
/// Optional username required for MQTT authentication.
public string? Username { get; set; }
/// Optional password required for MQTT authentication.
public string? Password { get; set; }
/// Optional bearer token accepted for MQTT authentication.
public string? Token { get; set; }
/// Authentication timeout in seconds for MQTT CONNECT processing.
public double AuthTimeout { get; set; }
// TLS
/// Path to the server certificate used for MQTT TLS.
public string? TlsCert { get; set; }
/// Path to the private key used for MQTT TLS.
public string? TlsKey { get; set; }
/// Path to the CA certificate bundle used to validate peer certificates.
public string? TlsCaCert { get; set; }
/// Enables client certificate verification for MQTT TLS connections.
public bool TlsVerify { get; set; }
/// TLS handshake timeout in seconds for MQTT clients.
public double TlsTimeout { get; set; } = 2.0;
/// Enables TLS certificate subject mapping to users.
public bool TlsMap { get; set; }
/// Set of pinned client certificate fingerprints allowed for MQTT connections.
public HashSet? TlsPinnedCerts { get; set; }
// JetStream integration
/// JetStream domain used by MQTT-backed streams and consumers.
public string? JsDomain { get; set; }
/// Replica count for MQTT-created JetStream streams.
public int StreamReplicas { get; set; }
/// Replica count for MQTT-created JetStream consumers.
public int ConsumerReplicas { get; set; }
/// Stores MQTT JetStream consumer state in memory when enabled.
public bool ConsumerMemoryStorage { get; set; }
/// Idle timeout after which inactive MQTT consumers are cleaned up.
public TimeSpan ConsumerInactiveThreshold { get; set; }
// QoS
/// Maximum time to wait for QoS acknowledgements before redelivery.
public TimeSpan AckWait { get; set; } = TimeSpan.FromSeconds(30);
/// Maximum number of outstanding unacknowledged QoS messages per consumer.
public ushort MaxAckPending { get; set; }
/// Timeout for internal JetStream API requests made by MQTT components.
public TimeSpan JsApiTimeout { get; set; } = TimeSpan.FromSeconds(5);
/// Enables durable MQTT session persistence across reconnects.
public bool SessionPersistence { get; set; } = true;
/// Time-to-live for persisted MQTT session state.
public TimeSpan SessionTtl { get; set; } = TimeSpan.FromHours(1);
/// Enables sending PUBACK for QoS 1 publishes.
public bool Qos1PubAck { get; set; } = true;
/// Indicates whether MQTT TLS is configured with both certificate and key.
public bool HasTls => TlsCert != null && TlsKey != null;
}