namespace ZB.MOM.WW.OtOpcUa.Driver.TwinCAT;

/// <summary>
///     Filter system / infrastructure symbols out of a TwinCAT symbol-loader walk. TC PLC
///     runtimes export plumbing symbols alongside user-declared ones — <c>TwinCAT_SystemInfoVarList</c>,
///     constants, IO task images, motion-layer internals — that clutter an OPC UA address space
///     if exposed.
/// </summary>
public static class TwinCATSystemSymbolFilter
{
    /// <summary>Gets a value indicating whether a symbol is a system or infrastructure symbol.</summary>
    /// <param name="instancePath">The symbol instance path to check.</param>
    /// <returns><see langword="true"/> if the symbol is a system/infrastructure symbol that should be filtered out; otherwise <see langword="false"/>.</returns>
    public static bool IsSystemSymbol(string instancePath)
    {
        if (string.IsNullOrWhiteSpace(instancePath)) return true;

        // Runtime-exported info lists.
        if (instancePath.StartsWith("TwinCAT_SystemInfoVarList", StringComparison.OrdinalIgnoreCase)) return true;
        if (instancePath.StartsWith("TwinCAT_", StringComparison.OrdinalIgnoreCase)) return true;
        if (instancePath.StartsWith("Global_Version", StringComparison.OrdinalIgnoreCase)) return true;

        // Constants pool — read-only, no operator value.
        if (instancePath.StartsWith("Constants.", StringComparison.OrdinalIgnoreCase)) return true;

        // Anonymous / compiler-generated.
        if (instancePath.StartsWith("__", StringComparison.Ordinal)) return true;

        // Motion / NC internals routinely surfaced by the symbol loader.
        if (instancePath.StartsWith("Mc_", StringComparison.OrdinalIgnoreCase)) return true;

        return false;
    }
}
