using System.Net.Sockets;
using Akka.Actor;
using Akka.Cluster.Tools.PublishSubscribe;
using Akka.Event;
using ZB.MOM.WW.OtOpcUa.Commons.Types;
namespace ZB.MOM.WW.OtOpcUa.Runtime.Health;
///
/// Periodically pings a peer node's OPC UA endpoint (opc.tcp://peer:4840) and publishes
/// the result on the cluster's redundancy-state input topic so the admin RedundancyStateActor
/// can react.
///
/// The probe is a plain TCP connect to the OPC UA port with a short timeout — enough to detect
/// "is the OPC UA server process up and accepting connections?" A full secure-channel handshake
/// (Hello / Acknowledge) needs the OPC UA Client SDK and a session/PKI setup, which is more than
/// what the redundancy calculator needs. Upgrade to a real Hello probe if a deeper liveness signal
/// is ever required.
///
public sealed class PeerOpcUaProbeActor : ReceiveActor, IWithTimers
{
// Owned by ControlPlane.Redundancy.RedundancyStateActor; duplicated here to avoid a
// Runtime → ControlPlane project reference. Keep both literals in lock-step.
public const string RedundancyStateTopic = "redundancy-state";
public static readonly TimeSpan DefaultProbeInterval = TimeSpan.FromSeconds(10);
public static readonly TimeSpan DefaultConnectTimeout = TimeSpan.FromSeconds(2);
public const int DefaultOpcUaPort = 4840;
public sealed record OpcUaProbeResult(NodeId NodeId, bool Ok);
public sealed class Tick { public static readonly Tick Instance = new(); private Tick() { } }
private readonly NodeId _peer;
private readonly TimeSpan _interval;
private readonly TimeSpan _connectTimeout;
private readonly int _opcUaPort;
private readonly Action