namespace ZB.MOM.WW.OtOpcUa.Driver.Mqtt.SparkplugSimulator;

/// <summary>
///     Connection + identity settings for one simulated Sparkplug B edge node.
/// </summary>
/// <remarks>
///     Deliberately its own shape rather than a reuse of the driver's <c>MqttDriverOptions</c>: an edge
///     node is the driver's <i>counterparty</i>, and reusing the driver's options record would drag the
///     driver assembly into this project and blur which side of the wire a setting belongs to. The TLS
///     knobs mirror the driver's by name so a rig configured for one is configured for the other.
/// </remarks>
public sealed record SparkplugEdgeNodeOptions
{
    /// <summary>Broker hostname or IP.</summary>
    public string Host { get; init; } = "localhost";

    /// <summary>Broker TCP port.</summary>
    public int Port { get; init; } = 8883;

    /// <summary>Connect over TLS.</summary>
    public bool UseTls { get; init; } = true;

    /// <summary>
    ///     PEM CA file pinning the broker chain. <see langword="null"/>/empty falls back to the OS
    ///     trust store (or to <see cref="AllowUntrustedServerCertificate"/> when that is set).
    /// </summary>
    public string? CaCertificatePath { get; init; }

    /// <summary>Accept any broker certificate. Fixture escape hatch; never a deployment posture.</summary>
    public bool AllowUntrustedServerCertificate { get; init; }

    /// <summary>Broker username. The fixture broker runs <c>allow_anonymous false</c>.</summary>
    public string? Username { get; init; }

    /// <summary>Broker password.</summary>
    public string? Password { get; init; }

    /// <summary>The Sparkplug group id this node publishes under.</summary>
    public string GroupId { get; init; } = "Plant1";

    /// <summary>The Sparkplug edge-node id.</summary>
    public string EdgeNodeId { get; init; } = "EdgeA";

    /// <summary>
    ///     MQTT client id. Left unset a unique one is generated — two simulated nodes sharing a client
    ///     id would knock each other off the broker.
    /// </summary>
    public string? ClientId { get; init; }

    /// <summary>Bounded connect/publish deadline, in seconds.</summary>
    public int TimeoutSeconds { get; init; } = 15;

    /// <summary>
    ///     QoS for NBIRTH/DBIRTH/NDATA/DDATA/DDEATH. Sparkplug B publishes all of these at QoS 0
    ///     (only NDEATH — the broker-issued Will — and STATE are QoS 1), which is the default here.
    /// </summary>
    public int DataQos { get; init; }
}
