using System;
namespace ZB.MOM.WW.OtOpcUa.Host.OpcUa
{
///
/// Computes the OPC UA ServiceLevel byte from a baseline and runtime health inputs.
///
public sealed class ServiceLevelCalculator
{
///
/// Calculates the current ServiceLevel from a role-adjusted baseline and health state.
///
/// The role-adjusted baseline (e.g., 200 for primary, 150 for secondary).
/// Whether the MXAccess runtime connection is healthy.
/// Whether the Galaxy repository database is reachable.
/// A ServiceLevel byte between 0 and 255.
public byte Calculate(int baseLevel, bool mxAccessConnected, bool dbConnected)
{
if (!mxAccessConnected && !dbConnected)
return 0;
var level = baseLevel;
if (!mxAccessConnected)
level -= 100;
if (!dbConnected)
level -= 50;
return (byte)Math.Max(0, Math.Min(level, 255));
}
}
}