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

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

/// <summary>
///     Inputs for draft validation. Contains the draft's rows plus the minimum prior-generation
///     rows needed for cross-generation invariants (EquipmentUuid stability, UnsArea identity).
/// </summary>
public sealed class DraftSnapshot
{
    /// <summary>Gets the draft generation identifier.</summary>
    public required long GenerationId { get; init; }
    /// <summary>Gets the cluster identifier.</summary>
    public required string ClusterId { get; init; }

    /// <summary>
    ///     Cluster's Enterprise segment (UNS level 1). When set, <see cref="DraftValidator"/> uses
    ///     the actual length for path-length checks instead of a conservative 32-char upper bound.
    /// </summary>
    public string? Enterprise { get; init; }

    /// <summary>
    ///     Cluster's Site segment (UNS level 2). When set, <see cref="DraftValidator"/> uses the
    ///     actual length for path-length checks instead of a conservative 32-char upper bound.
    /// </summary>
    public string? Site { get; init; }

    /// <summary>Gets the list of OPC UA namespaces.</summary>
    public IReadOnlyList<Namespace> Namespaces { get; init; } = [];
    /// <summary>Gets the list of driver instances.</summary>
    public IReadOnlyList<DriverInstance> DriverInstances { get; init; } = [];
    /// <summary>Gets the list of devices.</summary>
    public IReadOnlyList<Device> Devices { get; init; } = [];
    /// <summary>Gets the list of UNS areas.</summary>
    public IReadOnlyList<UnsArea> UnsAreas { get; init; } = [];
    /// <summary>Gets the list of UNS lines.</summary>
    public IReadOnlyList<UnsLine> UnsLines { get; init; } = [];
    /// <summary>Gets the list of equipment.</summary>
    public IReadOnlyList<Equipment> Equipment { get; init; } = [];
    /// <summary>Gets the list of tags.</summary>
    public IReadOnlyList<Tag> Tags { get; init; } = [];

    /// <summary>Equipment-bound VirtualTags (script-derived signals). Shares the equipment NodeId space
    /// with Tags; the collision rule checks both.</summary>
    public IReadOnlyList<VirtualTag> VirtualTags { get; init; } = [];
    /// <summary>Gets the list of poll groups.</summary>
    public IReadOnlyList<PollGroup> PollGroups { get; init; } = [];

    /// <summary>Prior Equipment rows (any generation, same cluster) for stability checks.</summary>
    public IReadOnlyList<Equipment> PriorEquipment { get; init; } = [];

    /// <summary>Active reservations (<c>ReleasedAt IS NULL</c>) for pre-flight.</summary>
    public IReadOnlyList<ExternalIdReservation> ActiveReservations { get; init; } = [];
}
