namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway.Mapping;

/// <summary>
///     The OPC UA status codes this driver publishes, as named constants.
/// </summary>
/// <remarks>
///     <para>The driver layer is deliberately free of an OPC UA SDK reference, so status codes are spelled
///     as bare <c>uint</c>s. The cost of that is a value nobody checks against the name it is written
///     under — the defect class Gitea #497 found in six places across four drivers, one of them the
///     <c>BadNoData</c> in <see cref="SampleMapper"/> that was really <c>BadServerHalted</c>.</para>
///     <para><b>Named, not inline, on purpose.</b> <c>StatusCodeParityTests</c> guards these by reflecting
///     over <c>const uint</c> fields and comparing each against <c>Opc.Ua.StatusCodes</c> in the pinned SDK.
///     A literal written at a call site is invisible to that guard, which is exactly how
///     <see cref="GatewayQualityMapper"/> kept an incorrect <c>Good_LocalOverride</c> through every test it
///     had. Add a constant here rather than a literal in a <c>switch</c> arm.</para>
/// </remarks>
internal static class HistorianStatusCodes
{
    // ---- Good family ----

    /// <summary>The value is good; no qualification.</summary>
    public const uint Good = 0x00000000u;

    /// <summary>The value has been overridden locally (OPC DA quality 216).</summary>
    public const uint GoodLocalOverride = 0x00960000u;

    // ---- Uncertain family ----

    /// <summary>The value is uncertain; no specific reason.</summary>
    public const uint Uncertain = 0x40000000u;

    /// <summary>Communication has failed; the last known value is returned (OPC DA quality 68).</summary>
    public const uint UncertainLastUsableValue = 0x40900000u;

    /// <summary>The sensor is known not to be accurate (OPC DA quality 80).</summary>
    public const uint UncertainSensorNotAccurate = 0x40930000u;

    /// <summary>The value is outside the engineering-unit range for the sensor (OPC DA quality 84).</summary>
    public const uint UncertainEngineeringUnitsExceeded = 0x40940000u;

    /// <summary>The value is derived from fewer sources than required (OPC DA quality 88).</summary>
    public const uint UncertainSubNormal = 0x40950000u;

    // ---- Bad family ----

    /// <summary>The value is bad; no specific reason.</summary>
    public const uint Bad = 0x80000000u;

    /// <summary>A configuration problem prevents the value being produced (OPC DA quality 4).</summary>
    public const uint BadConfigurationError = 0x80890000u;

    /// <summary>The source is not connected (OPC DA quality 8).</summary>
    public const uint BadNotConnected = 0x808A0000u;

    /// <summary>The device reported a failure (OPC DA quality 12).</summary>
    public const uint BadDeviceFailure = 0x808B0000u;

    /// <summary>The sensor reported a failure (OPC DA quality 16).</summary>
    public const uint BadSensorFailure = 0x808C0000u;

    /// <summary>Communication with the source failed (OPC DA quality 20).</summary>
    public const uint BadCommunicationError = 0x80050000u;

    /// <summary>The source is out of service (OPC DA quality 24).</summary>
    public const uint BadOutOfService = 0x808D0000u;

    /// <summary>No initial value has arrived from the source yet (OPC DA quality 32).</summary>
    public const uint BadWaitingForInitialData = 0x80320000u;

    /// <summary>
    ///     The historian returned no data for the requested tag/interval. Distinct from a transport
    ///     failure: the query succeeded and the answer was empty.
    /// </summary>
    public const uint BadNoData = 0x809B0000u;
}
