namespace ZB.MOM.WW.ScadaBridge.Commons.Types.DataConnections;

/// <summary>
/// OPC UA endpoint configuration.
/// </summary>
public sealed class OpcUaEndpointConfig
{
    // Connection
    /// <summary>
    /// The OPC UA endpoint URL.
    /// </summary>
    public string EndpointUrl { get; set; } = "";
    /// <summary>
    /// The security mode for the connection.
    /// </summary>
    public OpcUaSecurityMode SecurityMode { get; set; } = OpcUaSecurityMode.None;
    /// <summary>
    /// Whether to automatically accept untrusted certificates.
    /// </summary>
    public bool AutoAcceptUntrustedCerts { get; set; } = true;

    // Timing
    /// <summary>
    /// Session timeout in milliseconds.
    /// </summary>
    public int SessionTimeoutMs { get; set; } = 60000;
    /// <summary>
    /// Operation timeout in milliseconds.
    /// </summary>
    public int OperationTimeoutMs { get; set; } = 15000;

    // Subscription
    /// <summary>
    /// Publishing interval in milliseconds.
    /// </summary>
    public int PublishingIntervalMs { get; set; } = 1000;
    /// <summary>
    /// Sampling interval in milliseconds.
    /// </summary>
    public int SamplingIntervalMs { get; set; } = 1000;
    /// <summary>
    /// Queue size for the subscription.
    /// </summary>
    public int QueueSize { get; set; } = 10;
    /// <summary>
    /// Keep-alive count for the subscription.
    /// </summary>
    public int KeepAliveCount { get; set; } = 10;
    /// <summary>
    /// Lifetime count for the subscription.
    /// </summary>
    public int LifetimeCount { get; set; } = 30;
    /// <summary>
    /// Maximum notifications per publish.
    /// </summary>
    public int MaxNotificationsPerPublish { get; set; } = 100;
    /// <summary>
    /// Whether to discard oldest notifications when queue is full.
    /// </summary>
    public bool DiscardOldest { get; set; } = true;
    /// <summary>
    /// Subscription priority level.
    /// </summary>
    public byte SubscriptionPriority { get; set; } = 0;
    /// <summary>
    /// Display name for the subscription.
    /// </summary>
    public string SubscriptionDisplayName { get; set; } = "ScadaBridge";
    /// <summary>
    /// Maximum monitored items placed on a single OPC UA subscription before the
    /// adapter shards onto an additional subscription. Item-count ceilings are a
    /// property of the target server, so this is per endpoint rather than global.
    /// A site sized at 37,500 tags shards into 8 subscriptions at the default.
    /// Values &lt;= 0 are treated as the default.
    /// </summary>
    public int MaxMonitoredItemsPerSubscription { get; set; } = 5000;

    // Read / filter
    /// <summary>
    /// Timestamps to return in read operations.
    /// </summary>
    public OpcUaTimestampsToReturn TimestampsToReturn { get; set; } = OpcUaTimestampsToReturn.Source;
    /// <summary>
    /// Deadband configuration for filtering notifications.
    /// </summary>
    public OpcUaDeadbandConfig? Deadband { get; set; }

    // Authentication (optional; null = anonymous)
    /// <summary>
    /// User identity configuration for authentication.
    /// </summary>
    public OpcUaUserIdentityConfig? UserIdentity { get; set; }

    // Heartbeat (optional)
    /// <summary>
    /// Heartbeat configuration for connection monitoring.
    /// </summary>
    public OpcUaHeartbeatConfig? Heartbeat { get; set; }
}
