using Opc.Ua;
namespace ZB.MOM.WW.OtOpcUa.OpcUaServer;
///
/// The Part 13 processed reads are evaluated under (#677), and the rule for a
/// client-supplied one in ReadProcessedDetails.
///
///
///
/// The aggregate evaluators (AggregateEvaluator / TimeWeightedAggregator in
/// Driver.Historian.Sql.Common) are written against fixed settings, not parameterised: Uncertain time counts as
/// Good ( = false) in the time-weighted family; the per-sample Average / Minimum /
/// Maximum / Range / *ActualTime / Count are defined by Part 13 over Good values whatever this setting (#684), as the
/// SDK computes them under it; an interval is Good only when all of
/// it is ( = 100) and Bad only when none of it is non-Bad
/// ( = 100), otherwise UncertainDataSubNormal; the value past the last sample
/// is held (stepped, = false). These are also the SDK's own server defaults
/// (AggregateManager.GetDefaultConfiguration), which a test pins.
///
///
/// A request asking for UseServerCapabilitiesDefaults, or spelling out exactly these values, is served;
/// any other configuration is refused per node with BadAggregateConfigurationRejected rather than silently
/// answered under settings the client did not ask for (it used to be ignored).
///
///
public static class ServerAggregateConfiguration
{
/// Uncertain data is not treated as Bad.
public const bool TreatUncertainAsBad = false;
/// An interval is Bad only when 100 % of it is Bad.
public const byte PercentDataBad = 100;
/// An interval is Good only when 100 % of it is Good.
public const byte PercentDataGood = 100;
/// The value past the last sample is held (stepped), not sloped.
public const bool UseSlopedExtrapolation = false;
/// The server defaults as an (explicit values, not "use defaults").
public static AggregateConfiguration Defaults => new()
{
UseServerCapabilitiesDefaults = false,
TreatUncertainAsBad = TreatUncertainAsBad,
PercentDataBad = PercentDataBad,
PercentDataGood = PercentDataGood,
UseSlopedExtrapolation = UseSlopedExtrapolation,
};
///
/// True when a processed read with can be served: none supplied,
/// UseServerCapabilitiesDefaults, or every setting equal to the server's.
///
/// The request's configuration (may be null).
/// Whether to serve; false ⇒ BadAggregateConfigurationRejected.
public static bool IsServable(AggregateConfiguration? requested) =>
requested is null
|| requested.UseServerCapabilitiesDefaults
|| (requested.TreatUncertainAsBad == TreatUncertainAsBad
&& requested.PercentDataBad == PercentDataBad
&& requested.PercentDataGood == PercentDataGood
&& requested.UseSlopedExtrapolation == UseSlopedExtrapolation);
}