using System;
namespace ZB.MOM.WW.OtOpcUa.Host.Domain
{
///
/// Value-Timestamp-Quality triplet for tag data. (MXA-003, OPC-007)
///
public readonly struct Vtq : IEquatable
{
///
/// Gets the runtime value returned for the Galaxy attribute.
///
public object? Value { get; }
///
/// Gets the timestamp associated with the runtime value.
///
public DateTime Timestamp { get; }
///
/// Gets the quality classification that tells OPC UA clients whether the value is usable.
///
public Quality Quality { get; }
///
/// Initializes a new instance of the struct for a Galaxy attribute value.
///
/// The runtime value returned by MXAccess.
/// The timestamp assigned to the runtime value.
/// The quality classification for the runtime value.
public Vtq(object? value, DateTime timestamp, Quality quality)
{
Value = value;
Timestamp = timestamp;
Quality = quality;
}
///
/// Creates a good-quality VTQ snapshot for a successfully read or subscribed attribute value.
///
/// The runtime value to wrap.
/// A VTQ carrying the provided value with the current UTC timestamp and good quality.
public static Vtq Good(object? value)
{
return new Vtq(value, DateTime.UtcNow, Quality.Good);
}
///
/// Creates a bad-quality VTQ snapshot when no usable runtime value is available.
///
/// The specific bad quality reason to expose to clients.
/// A VTQ with no value, the current UTC timestamp, and the requested bad quality.
public static Vtq Bad(Quality quality = Quality.Bad)
{
return new Vtq(null, DateTime.UtcNow, quality);
}
///
/// Creates an uncertain VTQ snapshot when the runtime value exists but should be treated cautiously.
///
/// The runtime value to wrap.
/// A VTQ carrying the provided value with the current UTC timestamp and uncertain quality.
public static Vtq Uncertain(object? value)
{
return new Vtq(value, DateTime.UtcNow, Quality.Uncertain);
}
///
/// Compares two VTQ snapshots for exact value, timestamp, and quality equality.
///
/// The other VTQ snapshot to compare.
/// when all fields match; otherwise, .
public bool Equals(Vtq other)
{
return Equals(Value, other.Value) && Timestamp == other.Timestamp && Quality == other.Quality;
}
///
public override bool Equals(object? obj)
{
return obj is Vtq other && Equals(other);
}
///
public override int GetHashCode()
{
return HashCode.Combine(Value, Timestamp, Quality);
}
///
public override string ToString()
{
return $"Vtq({Value}, {Timestamp:O}, {Quality})";
}
}
}