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

public class DataConnection
{
    /// <summary>Gets or sets the database primary key.</summary>
    public int Id { get; set; }
    /// <summary>Gets or sets the owning site's id.</summary>
    public int SiteId { get; set; }
    /// <summary>Gets or sets the unique name of this data connection within the site.</summary>
    public string Name { get; set; }
    /// <summary>Gets or sets the protocol type string (e.g. "OpcUa").</summary>
    public string Protocol { get; set; }
    /// <summary>Gets or sets the primary protocol-specific configuration JSON.</summary>
    public string? PrimaryConfiguration { get; set; }
    /// <summary>Gets or sets the backup protocol-specific configuration JSON used on failover.</summary>
    public string? BackupConfiguration { get; set; }
    /// <summary>Gets or sets the number of failover retry attempts before the connection is marked failed.</summary>
    public int FailoverRetryCount { get; set; } = 3;

    /// <summary>
    /// Initializes a new <see cref="DataConnection"/> with the required fields.
    /// </summary>
    /// <param name="name">Unique name of the connection within the site.</param>
    /// <param name="protocol">Protocol type string (e.g. "OpcUa").</param>
    /// <param name="siteId">Id of the owning site.</param>
    public DataConnection(string name, string protocol, int siteId)
    {
        Name = name ?? throw new ArgumentNullException(nameof(name));
        Protocol = protocol ?? throw new ArgumentNullException(nameof(protocol));
        SiteId = siteId;
    }
}
