namespace ScadaLink.Commons.Entities.Templates;

public class TemplateScript
{
    public int Id { get; set; }
    public int TemplateId { get; set; }
    public string Name { get; set; }
    public bool IsLocked { get; set; }
    public string Code { get; set; }
    public string? TriggerType { get; set; }
    public string? TriggerConfiguration { get; set; }
    public string? ParameterDefinitions { get; set; }
    public string? ReturnDefinition { get; set; }
    public TimeSpan? MinTimeBetweenRuns { 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 script. When true, derived templates may not override
    /// the script body — 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; }

    public TemplateScript(string name, string code)
    {
        Name = name ?? throw new ArgumentNullException(nameof(name));
        Code = code ?? throw new ArgumentNullException(nameof(code));
    }
}
