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

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

public class Instance
{
    /// <summary>Primary key.</summary>
    public int Id { get; set; }
    /// <summary>Foreign key to the template this instance is based on.</summary>
    public int TemplateId { get; set; }
    /// <summary>Foreign key to the site where this instance is deployed.</summary>
    public int SiteId { get; set; }
    /// <summary>Optional foreign key to the organisational area this instance belongs to.</summary>
    public int? AreaId { get; set; }
    /// <summary>System-wide unique name that identifies this instance.</summary>
    public string UniqueName { get; set; }
    /// <summary>Current lifecycle state of the instance.</summary>
    public InstanceState State { get; set; }
    /// <summary>Per-attribute value overrides applied on top of the template defaults.</summary>
    public ICollection<InstanceAttributeOverride> AttributeOverrides { get; set; } = new List<InstanceAttributeOverride>();
    /// <summary>Per-alarm configuration overrides applied on top of the template defaults.</summary>
    public ICollection<InstanceAlarmOverride> AlarmOverrides { get; set; } = new List<InstanceAlarmOverride>();
    /// <summary>Data-connection bindings that map template tags to site data sources.</summary>
    public ICollection<InstanceConnectionBinding> ConnectionBindings { get; set; } = new List<InstanceConnectionBinding>();
    /// <summary>Per-instance overrides of template-defined native alarm source bindings.</summary>
    public ICollection<InstanceNativeAlarmSourceOverride> NativeAlarmSourceOverrides { get; set; } = new List<InstanceNativeAlarmSourceOverride>();

    /// <summary>
    /// Initializes a new instance with the required unique name.
    /// </summary>
    /// <param name="uniqueName">System-wide unique name for this instance.</param>
    public Instance(string uniqueName)
    {
        UniqueName = uniqueName ?? throw new ArgumentNullException(nameof(uniqueName));
    }
}
