using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates; using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories; using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services; using ZB.MOM.WW.ScadaBridge.Commons.Types; namespace ZB.MOM.WW.ScadaBridge.TemplateEngine; /// /// Core service for Template Engine operations. /// Covers CRUD for templates and their members (attributes, alarms, scripts, compositions), /// inheritance and composition rules, override/locking validation, collision detection, and acyclicity enforcement. /// public class TemplateService { private readonly ITemplateEngineRepository _repository; private readonly IAuditService _auditService; /// /// Initializes a new instance of the TemplateService class. /// /// Template engine repository for data access. /// Service for audit logging. public TemplateService(ITemplateEngineRepository repository, IAuditService auditService) { _repository = repository ?? throw new ArgumentNullException(nameof(repository)); _auditService = auditService ?? throw new ArgumentNullException(nameof(auditService)); } // ======================================================================== // WP-1: Template CRUD with Inheritance // ======================================================================== /// /// Creates a new template with optional inheritance and folder assignment. /// /// Name of the template. /// Optional description. /// Optional ID of the parent template for inheritance. /// Username of the user creating the template. /// Optional ID of the folder to place the template in. /// Cancellation token. /// Result containing the created template or failure message. public async Task> CreateTemplateAsync( string name, string? description, int? parentTemplateId, string user, int? folderId = null, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(name)) return Result