using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;

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

public class TemplateAlarm
{
    /// <summary>Database primary key.</summary>
    public int Id { get; set; }
    /// <summary>Foreign key to the owning <see cref="Template"/>.</summary>
    public int TemplateId { get; set; }
    /// <summary>Unique alarm name within the template.</summary>
    public string Name { get; set; }
    /// <summary>Optional human-readable description of the alarm.</summary>
    public string? Description { get; set; }
    /// <summary>Alarm priority level; lower values indicate higher priority.</summary>
    public int PriorityLevel { get; set; }
    /// <summary>When true, this alarm is locked and cannot be overridden in derived templates.</summary>
    public bool IsLocked { get; set; }
    /// <summary>Type of trigger condition that activates this alarm.</summary>
    public AlarmTriggerType TriggerType { get; set; }
    /// <summary>JSON-serialized trigger configuration specific to the <see cref="TriggerType"/>.</summary>
    public string? TriggerConfiguration { get; set; }
    /// <summary>Optional ID of the script to execute when the alarm triggers.</summary>
    public int? OnTriggerScriptId { get; set; }

    /// <summary>
    /// True when this row was copied from the base template and has not been
    /// overridden on the derived template. Changes to the base flow downward
    /// for inherited rows; an explicit override flips this to false.
    /// Always false on base (non-derived) templates.
    /// </summary>
    public bool IsInherited { get; set; }

    /// <summary>
    /// Set on a base alarm. When true, derived templates may not override the
    /// alarm — the row is rendered readonly with a 🔒 in the derived UI, and
    /// any attempt to update it through the API is rejected.
    /// </summary>
    public bool LockedInDerived { get; set; }

    /// <summary>
    /// Initializes a new <see cref="TemplateAlarm"/> with the specified name.
    /// </summary>
    /// <param name="name">The unique alarm name within the template.</param>
    public TemplateAlarm(string name)
    {
        Name = name ?? throw new ArgumentNullException(nameof(name));
    }
}
