using ZB.MOM.WW.OtOpcUa.Configuration.Enums;

namespace ZB.MOM.WW.OtOpcUa.Configuration.Entities;

/// <summary>
///     Top-level deployment unit. 1 or 2 <see cref="ClusterNode"/> members.
///     Per <c>config-db-schema.md</c> ServerCluster table.
/// </summary>
public sealed class ServerCluster
{
    /// <summary>Stable logical ID, e.g. "LINE3-OPCUA".</summary>
    public required string ClusterId { get; set; }

    /// <summary>Gets or sets the display name for the server cluster.</summary>
    public required string Name { get; set; }

    /// <summary>UNS level 1. Canonical org value: "zb".</summary>
    public required string Enterprise { get; set; }

    /// <summary>UNS level 2, e.g. "warsaw-west".</summary>
    public required string Site { get; set; }

    /// <summary>Gets or sets the number of nodes in the cluster.</summary>
    public byte NodeCount { get; set; }

    /// <summary>Gets or sets the redundancy mode for the cluster.</summary>
    public required RedundancyMode RedundancyMode { get; set; }

    /// <summary>Gets or sets a value indicating whether the cluster is enabled.</summary>
    public bool Enabled { get; set; } = true;

    /// <summary>Gets or sets optional notes about the cluster.</summary>
    public string? Notes { get; set; }

    /// <summary>Gets or sets the UTC timestamp when the cluster was created.</summary>
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    /// <summary>Gets or sets the user who created the cluster.</summary>
    public required string CreatedBy { get; set; }

    /// <summary>Gets or sets the UTC timestamp when the cluster was last modified.</summary>
    public DateTime? ModifiedAt { get; set; }

    /// <summary>Gets or sets the user who last modified the cluster.</summary>
    public string? ModifiedBy { get; set; }

    // Navigation
    /// <summary>Gets or sets the collection of cluster nodes.</summary>
    public ICollection<ClusterNode> Nodes { get; set; } = [];
    /// <summary>Gets or sets the collection of root-level Raw-tree folders in the cluster.</summary>
    public ICollection<RawFolder> RawFolders { get; set; } = [];
}
