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

/// <summary>
/// Per-instance override of a template-defined native alarm source. The source
/// reference is the field that varies per physical instance (Tank01 vs Tank02),
/// so per-instance override is the common case. Mirrors
/// <c>InstanceAlarmOverride</c>; a null override field leaves the inherited
/// value unchanged.
/// </summary>
public class InstanceNativeAlarmSourceOverride
{
    /// <summary>Primary key.</summary>
    public int Id { get; set; }
    /// <summary>Foreign key to the owning instance.</summary>
    public int InstanceId { get; set; }
    /// <summary>
    /// Canonical name of the native alarm source being overridden — matches
    /// <c>ResolvedNativeAlarmSource.CanonicalName</c> after flattening.
    /// </summary>
    public string SourceCanonicalName { get; set; }
    /// <summary>Overrides the connection name when set; null = keep inherited.</summary>
    public string? ConnectionNameOverride { get; set; }
    /// <summary>Overrides the source reference when set; null = keep inherited.</summary>
    public string? SourceReferenceOverride { get; set; }
    /// <summary>Overrides the condition filter when set; null = keep inherited.</summary>
    public string? ConditionFilterOverride { get; set; }

    /// <summary>Initializes a new override for the specified source binding.</summary>
    /// <param name="sourceCanonicalName">Canonical name of the source to override.</param>
    public InstanceNativeAlarmSourceOverride(string sourceCanonicalName) =>
        SourceCanonicalName = sourceCanonicalName ?? throw new ArgumentNullException(nameof(sourceCanonicalName));
}
