using ScadaLink.Commons.Entities.Instances; using ScadaLink.Commons.Entities.Sites; using ScadaLink.Commons.Entities.Templates; using ScadaLink.Commons.Types; using ScadaLink.Commons.Types.Enums; using ScadaLink.Commons.Types.Flattening; namespace ScadaLink.TemplateEngine.Flattening; /// /// Implements the template flattening algorithm. /// Takes a template inheritance/composition graph plus instance overrides and connection bindings, /// and produces a fully resolved FlattenedConfiguration. /// /// Resolution order (most specific wins): /// 1. Instance overrides (highest priority) /// 2. Child template (most derived first in inheritance chain) /// 3. Parent templates (walking up inheritance chain) /// 4. Composed modules (recursively flattened with path-qualified canonical names) /// /// Locked fields cannot be overridden by instance overrides. /// public class FlatteningService { /// /// Produces a fully flattened configuration for an instance. /// /// The instance to flatten. /// /// The inheritance chain from most-derived to root (index 0 = the instance's template, /// last = the ultimate base template). Each template includes its own attributes, alarms, scripts. /// /// /// Map of template ID → list of compositions (composed module definitions). /// For each composition, the key is the parent template ID and the value includes the /// composed template's resolved chain. /// /// /// Map of composed template ID → its inheritance chain (same format as templateChain). /// /// /// Available data connections for resolving connection bindings. /// /// A Result containing the FlattenedConfiguration or an error message. public Result Flatten( Instance instance, IReadOnlyList