using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy.ParityTests;
///
/// Same shape as Driver.Galaxy.E2E.RecordingAddressSpaceBuilder; duplicated
/// here so the parity-tests project doesn't take a hard project reference on the
/// E2E project (which would double-register E2E test classes during discovery).
///
public sealed class RecordingAddressSpaceBuilder : IAddressSpaceBuilder
{
public List Folders { get; } = new();
public List Variables { get; } = new();
public List Properties { get; } = new();
public List AlarmConditions { get; } = new();
public List AlarmTransitions { get; } = new();
public IAddressSpaceBuilder Folder(string browseName, string displayName)
{
Folders.Add(new RecordedFolder(browseName, displayName));
return this;
}
public IVariableHandle Variable(string browseName, string displayName, DriverAttributeInfo attributeInfo)
{
Variables.Add(new RecordedVariable(browseName, displayName, attributeInfo));
return new RecordedVariableHandle(attributeInfo.FullName, AlarmConditions, AlarmTransitions);
}
public void AddProperty(string browseName, DriverDataType dataType, object? value)
=> Properties.Add(new RecordedProperty(browseName, dataType, value));
public sealed record RecordedFolder(string BrowseName, string DisplayName);
public sealed record RecordedVariable(string BrowseName, string DisplayName, DriverAttributeInfo AttributeInfo);
public sealed record RecordedProperty(string BrowseName, DriverDataType DataType, object? Value);
public sealed record RecordedAlarmCondition(string SourceNodeId, AlarmConditionInfo Info);
public sealed record RecordedAlarmTransition(string SourceNodeId, AlarmEventArgs Args);
private sealed class RecordedVariableHandle(
string fullReference,
List conditions,
List transitions) : IVariableHandle
{
public string FullReference => fullReference;
public IAlarmConditionSink MarkAsAlarmCondition(AlarmConditionInfo info)
{
conditions.Add(new RecordedAlarmCondition(fullReference, info));
return new RecordingSink(fullReference, transitions);
}
private sealed class RecordingSink(
string sourceNodeId, List transitions) : IAlarmConditionSink
{
public void OnTransition(AlarmEventArgs args)
=> transitions.Add(new RecordedAlarmTransition(sourceNodeId, args));
}
}
}