using ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
using ZB.MOM.WW.OtOpcUa.OpcUaServer;
namespace ZB.MOM.WW.OtOpcUa.Host.Configuration;
///
/// The one Gitea #717 startup rule the options validator cannot see: OpcUa:Redundancy:Mode=Warm needs the
/// driver role (the validator is registered only on driver nodes, so on any other node it would never run).
///
public static class OpcUaRedundancyStartupGuard
{
/// Fails host start when a node without the driver role is configured Warm.
/// The raw OpcUa:Redundancy:Mode value.
/// Whether this node carries the driver role.
/// Warm without the driver role.
public static void RequireDriverRoleForWarm(string? configuredMode, bool hasDriver)
{
if (hasDriver) return;
var options = new OpcUaRedundancyOptions { Mode = configuredMode ?? string.Empty };
if (options.TryParseMode(out var mode) && mode == OpcUaRedundancyMode.Warm)
{
throw new InvalidOperationException(
"OpcUa:Redundancy:Mode is Warm on a node without the driver role; Warm redundancy needs the driver role "
+ "(the OPC UA endpoint is served by driver nodes only). Remove the setting or add the driver role.");
}
}
}