using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates; namespace ZB.MOM.WW.ScadaBridge.TemplateEngine; /// /// Detects cycles in template inheritance and composition graphs. /// Covers: self-inheritance, circular inheritance chains, self-composition, /// circular composition chains, and cross-graph (inheritance + composition) cycles. /// public static class CycleDetector { /// /// Builds an Id-keyed lookup that tolerates duplicate Ids in the input list /// (e.g. multiple not-yet-saved templates all carrying Id 0). On a duplicate /// the first occurrence wins — graph walks only need one representative node /// per Id, and a real cycle through any duplicate would still be reachable. /// A plain ToDictionary(t => t.Id) would instead throw ArgumentException. /// /// All templates to build lookup from. /// A dictionary keyed by template Id; on duplicate Ids the first occurrence wins. internal static Dictionary BuildLookup(IReadOnlyList