namespace ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates;

public class Template
{
    /// <summary>
    /// The unique identifier for the template.
    /// </summary>
    public int Id { get; set; }
    /// <summary>
    /// The name of the template.
    /// </summary>
    public string Name { get; set; }
    /// <summary>
    /// Optional description of the template.
    /// </summary>
    public string? Description { get; set; }
    /// <summary>
    /// The identifier of the parent template, if this template inherits from another.
    /// </summary>
    public int? ParentTemplateId { get; set; }
    /// <summary>
    /// The identifier of the folder containing this template.
    /// </summary>
    public int? FolderId { get; set; }
    /// <summary>
    /// Collection of attributes defined in this template.
    /// </summary>
    public ICollection<TemplateAttribute> Attributes { get; set; } = new List<TemplateAttribute>();
    /// <summary>
    /// Collection of alarms defined in this template.
    /// </summary>
    public ICollection<TemplateAlarm> Alarms { get; set; } = new List<TemplateAlarm>();
    /// <summary>
    /// Collection of scripts defined in this template.
    /// </summary>
    public ICollection<TemplateScript> Scripts { get; set; } = new List<TemplateScript>();
    /// <summary>
    /// Collection of compositions defined in this template.
    /// </summary>
    public ICollection<TemplateComposition> Compositions { get; set; } = new List<TemplateComposition>();
    /// <summary>
    /// Collection of native alarm source bindings defined in this template
    /// (read-only mirrors of OPC UA A&amp;C / MxAccess Gateway alarm feeds).
    /// </summary>
    public ICollection<TemplateNativeAlarmSource> NativeAlarmSources { get; set; } = new List<TemplateNativeAlarmSource>();

    /// <summary>
    /// True when this template was auto-derived to back a TemplateComposition
    /// slot. Derived templates inherit from a base (see <see cref="ParentTemplateId"/>),
    /// are owned by their composition row (see <see cref="OwnerCompositionId"/>),
    /// and are hidden from the main template tree by default.
    /// </summary>
    public bool IsDerived { get; set; }

    /// <summary>
    /// Back-reference to the <see cref="TemplateComposition"/> that owns this
    /// derived template. Non-null only when <see cref="IsDerived"/>; cascade-
    /// delete when the composition is removed. Always null on base templates.
    /// </summary>
    public int? OwnerCompositionId { get; set; }

    /// <summary>
    /// Initializes a new instance of the Template with the specified name.
    /// </summary>
    /// <param name="name">The name of the template.</param>
    public Template(string name)
    {
        Name = name ?? throw new ArgumentNullException(nameof(name));
    }
}
