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

/// <summary>
///     UNS level-5 entity. Only for drivers in Equipment-kind namespaces.
/// </summary>
public sealed class Equipment
{
    /// <summary>Gets or sets the row identifier for this equipment.</summary>
    public Guid EquipmentRowId { get; set; }

    /// <summary>
    ///     System-generated stable internal logical ID. Format: <c>'EQ-' + first 12 hex chars of EquipmentUuid</c>.
    ///     NEVER operator-supplied, NEVER in CSV imports, NEVER editable in Admin UI.
    /// </summary>
    public required string EquipmentId { get; set; }

    /// <summary>UUIDv4, IMMUTABLE across all generations of the same EquipmentId. Downstream-consumer join key.</summary>
    public Guid EquipmentUuid { get; set; }

    // v3: equipment no longer binds a driver or device. It references existing raw tags via
    // UnsTagReference and hosts VirtualTags + ScriptedAlarms. The old DriverInstanceId / DeviceId
    // binding columns are retired.

    /// <summary>Logical FK to <see cref="UnsLine.UnsLineId"/>.</summary>
    public required string UnsLineId { get; set; }

    /// <summary>UNS level 5 segment, matches <c>^[a-z0-9-]{1,32}$</c>.</summary>
    public required string Name { get; set; }

    // Operator-facing / external-system identifiers

    /// <summary>Operator colloquial id (e.g. "machine_001"). Unique within cluster. Required.</summary>
    public required string MachineCode { get; set; }

    /// <summary>ERP equipment id. Unique fleet-wide via <see cref="ExternalIdReservation"/>. Primary browse identifier in Admin UI.</summary>
    public string? ZTag { get; set; }

    /// <summary>SAP PM equipment id. Unique fleet-wide via <see cref="ExternalIdReservation"/>.</summary>
    public string? SAPID { get; set; }

    // OPC UA Companion Spec OPC 40010 Machinery Identification fields.
    // All nullable so equipment can be added before identity is fully captured.
    /// <summary>Gets or sets the manufacturer name for this equipment.</summary>
    public string? Manufacturer { get; set; }
    /// <summary>Gets or sets the model number or designation for this equipment.</summary>
    public string? Model { get; set; }
    /// <summary>Gets or sets the serial number for this equipment.</summary>
    public string? SerialNumber { get; set; }
    /// <summary>Gets or sets the hardware revision level for this equipment.</summary>
    public string? HardwareRevision { get; set; }
    /// <summary>Gets or sets the software revision level for this equipment.</summary>
    public string? SoftwareRevision { get; set; }
    /// <summary>Gets or sets the year of construction for this equipment.</summary>
    public short? YearOfConstruction { get; set; }
    /// <summary>Gets or sets the asset location information for this equipment.</summary>
    public string? AssetLocation { get; set; }
    /// <summary>Gets or sets the manufacturer URI for this equipment.</summary>
    public string? ManufacturerUri { get; set; }
    /// <summary>Gets or sets the device manual URI for this equipment.</summary>
    public string? DeviceManualUri { get; set; }

    /// <summary>Nullable hook for future schemas-repo template ID.</summary>
    public string? EquipmentClassRef { get; set; }

    /// <summary>Gets or sets whether this equipment is enabled.</summary>
    public bool Enabled { get; set; } = true;

    /// <summary>Optimistic concurrency token for last-write-wins detection in the v2 live-edit model.</summary>
    public byte[] RowVersion { get; set; } = Array.Empty<byte>();
}
