namespace ScadaLink.Commons.Entities.Templates;

public class Template
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string? Description { get; set; }
    public int? ParentTemplateId { get; set; }
    public int? FolderId { get; set; }
    public ICollection<TemplateAttribute> Attributes { get; set; } = new List<TemplateAttribute>();
    public ICollection<TemplateAlarm> Alarms { get; set; } = new List<TemplateAlarm>();
    public ICollection<TemplateScript> Scripts { get; set; } = new List<TemplateScript>();
    public ICollection<TemplateComposition> Compositions { get; set; } = new List<TemplateComposition>();

    /// <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; }

    public Template(string name)
    {
        Name = name ?? throw new ArgumentNullException(nameof(name));
    }
}
