// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using ZB.MOM.WW.OtOpcUa.Configuration;

#nullable disable

namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
{
    [DbContext(typeof(OtOpcUaConfigDbContext))]
    [Migration("20260417220857_AuthorizationGrants")]
    partial class AuthorizationGrants
    {
        /// <inheritdoc />
        protected override void BuildTargetModel(ModelBuilder modelBuilder)
        {
#pragma warning disable 612, 618
            modelBuilder
                .HasAnnotation("ProductVersion", "10.0.0")
                .HasAnnotation("Relational:MaxIdentifierLength", 128);

            SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNode", b =>
                {
                    b.Property<string>("NodeId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("ApplicationUri")
                        .IsRequired()
                        .HasMaxLength(256)
                        .HasColumnType("nvarchar(256)");

                    b.Property<string>("ClusterId")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<DateTime>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("datetime2(3)")
                        .HasDefaultValueSql("SYSUTCDATETIME()");

                    b.Property<string>("CreatedBy")
                        .IsRequired()
                        .HasMaxLength(128)
                        .HasColumnType("nvarchar(128)");

                    b.Property<int>("DashboardPort")
                        .HasColumnType("int");

                    b.Property<string>("DriverConfigOverridesJson")
                        .HasColumnType("nvarchar(max)");

                    b.Property<bool>("Enabled")
                        .HasColumnType("bit");

                    b.Property<string>("Host")
                        .IsRequired()
                        .HasMaxLength(255)
                        .HasColumnType("nvarchar(255)");

                    b.Property<DateTime?>("LastSeenAt")
                        .HasColumnType("datetime2(3)");

                    b.Property<int>("OpcUaPort")
                        .HasColumnType("int");

                    b.Property<string>("RedundancyRole")
                        .IsRequired()
                        .HasMaxLength(16)
                        .HasColumnType("nvarchar(16)");

                    b.Property<byte>("ServiceLevelBase")
                        .HasColumnType("tinyint");

                    b.HasKey("NodeId");

                    b.HasIndex("ApplicationUri")
                        .IsUnique()
                        .HasDatabaseName("UX_ClusterNode_ApplicationUri");

                    b.HasIndex("ClusterId")
                        .IsUnique()
                        .HasDatabaseName("UX_ClusterNode_Primary_Per_Cluster")
                        .HasFilter("[RedundancyRole] = 'Primary'");

                    b.ToTable("ClusterNode", (string)null);
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNodeCredential", b =>
                {
                    b.Property<Guid>("CredentialId")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uniqueidentifier")
                        .HasDefaultValueSql("NEWSEQUENTIALID()");

                    b.Property<DateTime>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("datetime2(3)")
                        .HasDefaultValueSql("SYSUTCDATETIME()");

                    b.Property<string>("CreatedBy")
                        .IsRequired()
                        .HasMaxLength(128)
                        .HasColumnType("nvarchar(128)");

                    b.Property<bool>("Enabled")
                        .HasColumnType("bit");

                    b.Property<string>("Kind")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("nvarchar(32)");

                    b.Property<string>("NodeId")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<DateTime?>("RotatedAt")
                        .HasColumnType("datetime2(3)");

                    b.Property<string>("Value")
                        .IsRequired()
                        .HasMaxLength(512)
                        .HasColumnType("nvarchar(512)");

                    b.HasKey("CredentialId");

                    b.HasIndex("Kind", "Value")
                        .IsUnique()
                        .HasDatabaseName("UX_ClusterNodeCredential_Value")
                        .HasFilter("[Enabled] = 1");

                    b.HasIndex("NodeId", "Enabled")
                        .HasDatabaseName("IX_ClusterNodeCredential_NodeId");

                    b.ToTable("ClusterNodeCredential", (string)null);
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNodeGenerationState", b =>
                {
                    b.Property<string>("NodeId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<long?>("CurrentGenerationId")
                        .HasColumnType("bigint");

                    b.Property<DateTime?>("LastAppliedAt")
                        .HasColumnType("datetime2(3)");

                    b.Property<string>("LastAppliedError")
                        .HasMaxLength(2048)
                        .HasColumnType("nvarchar(2048)");

                    b.Property<string>("LastAppliedStatus")
                        .HasMaxLength(16)
                        .HasColumnType("nvarchar(16)");

                    b.Property<DateTime?>("LastSeenAt")
                        .HasColumnType("datetime2(3)");

                    b.HasKey("NodeId");

                    b.HasIndex("CurrentGenerationId")
                        .HasDatabaseName("IX_ClusterNodeGenerationState_Generation");

                    b.ToTable("ClusterNodeGenerationState", (string)null);
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigAuditLog", b =>
                {
                    b.Property<long>("AuditId")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("bigint");

                    SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("AuditId"));

                    b.Property<string>("ClusterId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("DetailsJson")
                        .HasColumnType("nvarchar(max)");

                    b.Property<string>("EventType")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<long?>("GenerationId")
                        .HasColumnType("bigint");

                    b.Property<string>("NodeId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("Principal")
                        .IsRequired()
                        .HasMaxLength(128)
                        .HasColumnType("nvarchar(128)");

                    b.Property<DateTime>("Timestamp")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("datetime2(3)")
                        .HasDefaultValueSql("SYSUTCDATETIME()");

                    b.HasKey("AuditId");

                    b.HasIndex("GenerationId")
                        .HasDatabaseName("IX_ConfigAuditLog_Generation")
                        .HasFilter("[GenerationId] IS NOT NULL");

                    b.HasIndex("ClusterId", "Timestamp")
                        .IsDescending(false, true)
                        .HasDatabaseName("IX_ConfigAuditLog_Cluster_Time");

                    b.ToTable("ConfigAuditLog", null, t =>
                        {
                            t.HasCheckConstraint("CK_ConfigAuditLog_DetailsJson_IsJson", "DetailsJson IS NULL OR ISJSON(DetailsJson) = 1");
                        });
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigGeneration", b =>
                {
                    b.Property<long>("GenerationId")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("bigint");

                    SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("GenerationId"));

                    b.Property<string>("ClusterId")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<DateTime>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("datetime2(3)")
                        .HasDefaultValueSql("SYSUTCDATETIME()");

                    b.Property<string>("CreatedBy")
                        .IsRequired()
                        .HasMaxLength(128)
                        .HasColumnType("nvarchar(128)");

                    b.Property<string>("Notes")
                        .HasMaxLength(1024)
                        .HasColumnType("nvarchar(1024)");

                    b.Property<long?>("ParentGenerationId")
                        .HasColumnType("bigint");

                    b.Property<DateTime?>("PublishedAt")
                        .HasColumnType("datetime2(3)");

                    b.Property<string>("PublishedBy")
                        .HasMaxLength(128)
                        .HasColumnType("nvarchar(128)");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(16)
                        .HasColumnType("nvarchar(16)");

                    b.HasKey("GenerationId");

                    b.HasIndex("ClusterId")
                        .IsUnique()
                        .HasDatabaseName("UX_ConfigGeneration_Draft_Per_Cluster")
                        .HasFilter("[Status] = 'Draft'");

                    b.HasIndex("ParentGenerationId");

                    b.HasIndex("ClusterId", "Status", "GenerationId")
                        .IsDescending(false, false, true)
                        .HasDatabaseName("IX_ConfigGeneration_Cluster_Published");

                    SqlServerIndexBuilderExtensions.IncludeProperties(b.HasIndex("ClusterId", "Status", "GenerationId"), new[] { "PublishedAt" });

                    b.ToTable("ConfigGeneration", (string)null);
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.Device", b =>
                {
                    b.Property<Guid>("DeviceRowId")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uniqueidentifier")
                        .HasDefaultValueSql("NEWSEQUENTIALID()");

                    b.Property<string>("DeviceConfig")
                        .IsRequired()
                        .HasColumnType("nvarchar(max)");

                    b.Property<string>("DeviceId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("DriverInstanceId")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<bool>("Enabled")
                        .HasColumnType("bit");

                    b.Property<long>("GenerationId")
                        .HasColumnType("bigint");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(128)
                        .HasColumnType("nvarchar(128)");

                    b.HasKey("DeviceRowId");

                    b.HasIndex("GenerationId", "DeviceId")
                        .IsUnique()
                        .HasDatabaseName("UX_Device_Generation_LogicalId")
                        .HasFilter("[DeviceId] IS NOT NULL");

                    b.HasIndex("GenerationId", "DriverInstanceId")
                        .HasDatabaseName("IX_Device_Generation_Driver");

                    b.ToTable("Device", null, t =>
                        {
                            t.HasCheckConstraint("CK_Device_DeviceConfig_IsJson", "ISJSON(DeviceConfig) = 1");
                        });
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.DriverInstance", b =>
                {
                    b.Property<Guid>("DriverInstanceRowId")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uniqueidentifier")
                        .HasDefaultValueSql("NEWSEQUENTIALID()");

                    b.Property<string>("ClusterId")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("DriverConfig")
                        .IsRequired()
                        .HasColumnType("nvarchar(max)");

                    b.Property<string>("DriverInstanceId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("DriverType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("nvarchar(32)");

                    b.Property<bool>("Enabled")
                        .HasColumnType("bit");

                    b.Property<long>("GenerationId")
                        .HasColumnType("bigint");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(128)
                        .HasColumnType("nvarchar(128)");

                    b.Property<string>("NamespaceId")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.HasKey("DriverInstanceRowId");

                    b.HasIndex("ClusterId");

                    b.HasIndex("GenerationId", "ClusterId")
                        .HasDatabaseName("IX_DriverInstance_Generation_Cluster");

                    b.HasIndex("GenerationId", "DriverInstanceId")
                        .IsUnique()
                        .HasDatabaseName("UX_DriverInstance_Generation_LogicalId")
                        .HasFilter("[DriverInstanceId] IS NOT NULL");

                    b.HasIndex("GenerationId", "NamespaceId")
                        .HasDatabaseName("IX_DriverInstance_Generation_Namespace");

                    b.ToTable("DriverInstance", null, t =>
                        {
                            t.HasCheckConstraint("CK_DriverInstance_DriverConfig_IsJson", "ISJSON(DriverConfig) = 1");
                        });
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.Equipment", b =>
                {
                    b.Property<Guid>("EquipmentRowId")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uniqueidentifier")
                        .HasDefaultValueSql("NEWSEQUENTIALID()");

                    b.Property<string>("AssetLocation")
                        .HasMaxLength(256)
                        .HasColumnType("nvarchar(256)");

                    b.Property<string>("DeviceId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("DeviceManualUri")
                        .HasMaxLength(512)
                        .HasColumnType("nvarchar(512)");

                    b.Property<string>("DriverInstanceId")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<bool>("Enabled")
                        .HasColumnType("bit");

                    b.Property<string>("EquipmentClassRef")
                        .HasMaxLength(128)
                        .HasColumnType("nvarchar(128)");

                    b.Property<string>("EquipmentId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<Guid>("EquipmentUuid")
                        .HasColumnType("uniqueidentifier");

                    b.Property<long>("GenerationId")
                        .HasColumnType("bigint");

                    b.Property<string>("HardwareRevision")
                        .HasMaxLength(32)
                        .HasColumnType("nvarchar(32)");

                    b.Property<string>("MachineCode")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("Manufacturer")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("ManufacturerUri")
                        .HasMaxLength(512)
                        .HasColumnType("nvarchar(512)");

                    b.Property<string>("Model")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("nvarchar(32)");

                    b.Property<string>("SAPID")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("SerialNumber")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("SoftwareRevision")
                        .HasMaxLength(32)
                        .HasColumnType("nvarchar(32)");

                    b.Property<string>("UnsLineId")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<short?>("YearOfConstruction")
                        .HasColumnType("smallint");

                    b.Property<string>("ZTag")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.HasKey("EquipmentRowId");

                    b.HasIndex("GenerationId", "DriverInstanceId")
                        .HasDatabaseName("IX_Equipment_Generation_Driver");

                    b.HasIndex("GenerationId", "EquipmentId")
                        .IsUnique()
                        .HasDatabaseName("UX_Equipment_Generation_LogicalId")
                        .HasFilter("[EquipmentId] IS NOT NULL");

                    b.HasIndex("GenerationId", "EquipmentUuid")
                        .IsUnique()
                        .HasDatabaseName("UX_Equipment_Generation_Uuid");

                    b.HasIndex("GenerationId", "MachineCode")
                        .HasDatabaseName("IX_Equipment_Generation_MachineCode");

                    b.HasIndex("GenerationId", "SAPID")
                        .HasDatabaseName("IX_Equipment_Generation_SAPID")
                        .HasFilter("[SAPID] IS NOT NULL");

                    b.HasIndex("GenerationId", "UnsLineId")
                        .HasDatabaseName("IX_Equipment_Generation_Line");

                    b.HasIndex("GenerationId", "ZTag")
                        .HasDatabaseName("IX_Equipment_Generation_ZTag")
                        .HasFilter("[ZTag] IS NOT NULL");

                    b.HasIndex("GenerationId", "UnsLineId", "Name")
                        .IsUnique()
                        .HasDatabaseName("UX_Equipment_Generation_LinePath");

                    b.ToTable("Equipment", (string)null);
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ExternalIdReservation", b =>
                {
                    b.Property<Guid>("ReservationId")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uniqueidentifier")
                        .HasDefaultValueSql("NEWSEQUENTIALID()");

                    b.Property<string>("ClusterId")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<Guid>("EquipmentUuid")
                        .HasColumnType("uniqueidentifier");

                    b.Property<DateTime>("FirstPublishedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("datetime2(3)")
                        .HasDefaultValueSql("SYSUTCDATETIME()");

                    b.Property<string>("FirstPublishedBy")
                        .IsRequired()
                        .HasMaxLength(128)
                        .HasColumnType("nvarchar(128)");

                    b.Property<string>("Kind")
                        .IsRequired()
                        .HasMaxLength(16)
                        .HasColumnType("nvarchar(16)");

                    b.Property<DateTime>("LastPublishedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("datetime2(3)")
                        .HasDefaultValueSql("SYSUTCDATETIME()");

                    b.Property<string>("ReleaseReason")
                        .HasMaxLength(512)
                        .HasColumnType("nvarchar(512)");

                    b.Property<DateTime?>("ReleasedAt")
                        .HasColumnType("datetime2(3)");

                    b.Property<string>("ReleasedBy")
                        .HasMaxLength(128)
                        .HasColumnType("nvarchar(128)");

                    b.Property<string>("Value")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.HasKey("ReservationId");

                    b.HasIndex("EquipmentUuid")
                        .HasDatabaseName("IX_ExternalIdReservation_Equipment");

                    b.HasIndex("Kind", "Value")
                        .IsUnique()
                        .HasDatabaseName("UX_ExternalIdReservation_KindValue_Active")
                        .HasFilter("[ReleasedAt] IS NULL");

                    b.ToTable("ExternalIdReservation", (string)null);
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.Namespace", b =>
                {
                    b.Property<Guid>("NamespaceRowId")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uniqueidentifier")
                        .HasDefaultValueSql("NEWSEQUENTIALID()");

                    b.Property<string>("ClusterId")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<bool>("Enabled")
                        .HasColumnType("bit");

                    b.Property<long>("GenerationId")
                        .HasColumnType("bigint");

                    b.Property<string>("Kind")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("nvarchar(32)");

                    b.Property<string>("NamespaceId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("NamespaceUri")
                        .IsRequired()
                        .HasMaxLength(256)
                        .HasColumnType("nvarchar(256)");

                    b.Property<string>("Notes")
                        .HasMaxLength(1024)
                        .HasColumnType("nvarchar(1024)");

                    b.HasKey("NamespaceRowId");

                    b.HasIndex("ClusterId");

                    b.HasIndex("GenerationId", "ClusterId")
                        .HasDatabaseName("IX_Namespace_Generation_Cluster");

                    b.HasIndex("GenerationId", "NamespaceId")
                        .IsUnique()
                        .HasDatabaseName("UX_Namespace_Generation_LogicalId")
                        .HasFilter("[NamespaceId] IS NOT NULL");

                    b.HasIndex("GenerationId", "NamespaceUri")
                        .IsUnique()
                        .HasDatabaseName("UX_Namespace_Generation_NamespaceUri");

                    b.HasIndex("GenerationId", "ClusterId", "Kind")
                        .IsUnique()
                        .HasDatabaseName("UX_Namespace_Generation_Cluster_Kind");

                    b.HasIndex("GenerationId", "NamespaceId", "ClusterId")
                        .IsUnique()
                        .HasDatabaseName("UX_Namespace_Generation_LogicalId_Cluster")
                        .HasFilter("[NamespaceId] IS NOT NULL");

                    b.ToTable("Namespace", (string)null);
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.NodeAcl", b =>
                {
                    b.Property<Guid>("NodeAclRowId")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uniqueidentifier")
                        .HasDefaultValueSql("NEWSEQUENTIALID()");

                    b.Property<string>("ClusterId")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<long>("GenerationId")
                        .HasColumnType("bigint");

                    b.Property<string>("LdapGroup")
                        .IsRequired()
                        .HasMaxLength(256)
                        .HasColumnType("nvarchar(256)");

                    b.Property<string>("NodeAclId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("Notes")
                        .HasMaxLength(512)
                        .HasColumnType("nvarchar(512)");

                    b.Property<int>("PermissionFlags")
                        .HasColumnType("int");

                    b.Property<string>("ScopeId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("ScopeKind")
                        .IsRequired()
                        .HasMaxLength(16)
                        .HasColumnType("nvarchar(16)");

                    b.HasKey("NodeAclRowId");

                    b.HasIndex("GenerationId", "ClusterId")
                        .HasDatabaseName("IX_NodeAcl_Generation_Cluster");

                    b.HasIndex("GenerationId", "LdapGroup")
                        .HasDatabaseName("IX_NodeAcl_Generation_Group");

                    b.HasIndex("GenerationId", "NodeAclId")
                        .IsUnique()
                        .HasDatabaseName("UX_NodeAcl_Generation_LogicalId")
                        .HasFilter("[NodeAclId] IS NOT NULL");

                    b.HasIndex("GenerationId", "ScopeKind", "ScopeId")
                        .HasDatabaseName("IX_NodeAcl_Generation_Scope")
                        .HasFilter("[ScopeId] IS NOT NULL");

                    b.HasIndex("GenerationId", "ClusterId", "LdapGroup", "ScopeKind", "ScopeId")
                        .IsUnique()
                        .HasDatabaseName("UX_NodeAcl_Generation_GroupScope")
                        .HasFilter("[ScopeId] IS NOT NULL");

                    b.ToTable("NodeAcl", (string)null);
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.PollGroup", b =>
                {
                    b.Property<Guid>("PollGroupRowId")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uniqueidentifier")
                        .HasDefaultValueSql("NEWSEQUENTIALID()");

                    b.Property<string>("DriverInstanceId")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<long>("GenerationId")
                        .HasColumnType("bigint");

                    b.Property<int>("IntervalMs")
                        .HasColumnType("int");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(128)
                        .HasColumnType("nvarchar(128)");

                    b.Property<string>("PollGroupId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.HasKey("PollGroupRowId");

                    b.HasIndex("GenerationId", "DriverInstanceId")
                        .HasDatabaseName("IX_PollGroup_Generation_Driver");

                    b.HasIndex("GenerationId", "PollGroupId")
                        .IsUnique()
                        .HasDatabaseName("UX_PollGroup_Generation_LogicalId")
                        .HasFilter("[PollGroupId] IS NOT NULL");

                    b.ToTable("PollGroup", null, t =>
                        {
                            t.HasCheckConstraint("CK_PollGroup_IntervalMs_Min", "IntervalMs >= 50");
                        });
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", b =>
                {
                    b.Property<string>("ClusterId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<DateTime>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("datetime2(3)")
                        .HasDefaultValueSql("SYSUTCDATETIME()");

                    b.Property<string>("CreatedBy")
                        .IsRequired()
                        .HasMaxLength(128)
                        .HasColumnType("nvarchar(128)");

                    b.Property<bool>("Enabled")
                        .HasColumnType("bit");

                    b.Property<string>("Enterprise")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("nvarchar(32)");

                    b.Property<DateTime?>("ModifiedAt")
                        .HasColumnType("datetime2(3)");

                    b.Property<string>("ModifiedBy")
                        .HasMaxLength(128)
                        .HasColumnType("nvarchar(128)");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(128)
                        .HasColumnType("nvarchar(128)");

                    b.Property<byte>("NodeCount")
                        .HasColumnType("tinyint");

                    b.Property<string>("Notes")
                        .HasMaxLength(1024)
                        .HasColumnType("nvarchar(1024)");

                    b.Property<string>("RedundancyMode")
                        .IsRequired()
                        .HasMaxLength(16)
                        .HasColumnType("nvarchar(16)");

                    b.Property<string>("Site")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("nvarchar(32)");

                    b.HasKey("ClusterId");

                    b.HasIndex("Name")
                        .IsUnique()
                        .HasDatabaseName("UX_ServerCluster_Name");

                    b.HasIndex("Site")
                        .HasDatabaseName("IX_ServerCluster_Site");

                    b.ToTable("ServerCluster", null, t =>
                        {
                            t.HasCheckConstraint("CK_ServerCluster_RedundancyMode_NodeCount", "((NodeCount = 1 AND RedundancyMode = 'None') OR (NodeCount = 2 AND RedundancyMode IN ('Warm', 'Hot')))");
                        });
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.Tag", b =>
                {
                    b.Property<Guid>("TagRowId")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uniqueidentifier")
                        .HasDefaultValueSql("NEWSEQUENTIALID()");

                    b.Property<string>("AccessLevel")
                        .IsRequired()
                        .HasMaxLength(16)
                        .HasColumnType("nvarchar(16)");

                    b.Property<string>("DataType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("nvarchar(32)");

                    b.Property<string>("DeviceId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("DriverInstanceId")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("EquipmentId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("FolderPath")
                        .HasMaxLength(512)
                        .HasColumnType("nvarchar(512)");

                    b.Property<long>("GenerationId")
                        .HasColumnType("bigint");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(128)
                        .HasColumnType("nvarchar(128)");

                    b.Property<string>("PollGroupId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("TagConfig")
                        .IsRequired()
                        .HasColumnType("nvarchar(max)");

                    b.Property<string>("TagId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<bool>("WriteIdempotent")
                        .HasColumnType("bit");

                    b.HasKey("TagRowId");

                    b.HasIndex("GenerationId", "EquipmentId")
                        .HasDatabaseName("IX_Tag_Generation_Equipment")
                        .HasFilter("[EquipmentId] IS NOT NULL");

                    b.HasIndex("GenerationId", "TagId")
                        .IsUnique()
                        .HasDatabaseName("UX_Tag_Generation_LogicalId")
                        .HasFilter("[TagId] IS NOT NULL");

                    b.HasIndex("GenerationId", "DriverInstanceId", "DeviceId")
                        .HasDatabaseName("IX_Tag_Generation_Driver_Device");

                    b.HasIndex("GenerationId", "EquipmentId", "Name")
                        .IsUnique()
                        .HasDatabaseName("UX_Tag_Generation_EquipmentPath")
                        .HasFilter("[EquipmentId] IS NOT NULL");

                    b.HasIndex("GenerationId", "DriverInstanceId", "FolderPath", "Name")
                        .IsUnique()
                        .HasDatabaseName("UX_Tag_Generation_FolderPath")
                        .HasFilter("[EquipmentId] IS NULL");

                    b.ToTable("Tag", null, t =>
                        {
                            t.HasCheckConstraint("CK_Tag_TagConfig_IsJson", "ISJSON(TagConfig) = 1");
                        });
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.UnsArea", b =>
                {
                    b.Property<Guid>("UnsAreaRowId")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uniqueidentifier")
                        .HasDefaultValueSql("NEWSEQUENTIALID()");

                    b.Property<string>("ClusterId")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<long>("GenerationId")
                        .HasColumnType("bigint");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("nvarchar(32)");

                    b.Property<string>("Notes")
                        .HasMaxLength(512)
                        .HasColumnType("nvarchar(512)");

                    b.Property<string>("UnsAreaId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.HasKey("UnsAreaRowId");

                    b.HasIndex("ClusterId");

                    b.HasIndex("GenerationId", "ClusterId")
                        .HasDatabaseName("IX_UnsArea_Generation_Cluster");

                    b.HasIndex("GenerationId", "UnsAreaId")
                        .IsUnique()
                        .HasDatabaseName("UX_UnsArea_Generation_LogicalId")
                        .HasFilter("[UnsAreaId] IS NOT NULL");

                    b.HasIndex("GenerationId", "ClusterId", "Name")
                        .IsUnique()
                        .HasDatabaseName("UX_UnsArea_Generation_ClusterName");

                    b.ToTable("UnsArea", (string)null);
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.UnsLine", b =>
                {
                    b.Property<Guid>("UnsLineRowId")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uniqueidentifier")
                        .HasDefaultValueSql("NEWSEQUENTIALID()");

                    b.Property<long>("GenerationId")
                        .HasColumnType("bigint");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("nvarchar(32)");

                    b.Property<string>("Notes")
                        .HasMaxLength(512)
                        .HasColumnType("nvarchar(512)");

                    b.Property<string>("UnsAreaId")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.Property<string>("UnsLineId")
                        .HasMaxLength(64)
                        .HasColumnType("nvarchar(64)");

                    b.HasKey("UnsLineRowId");

                    b.HasIndex("GenerationId", "UnsAreaId")
                        .HasDatabaseName("IX_UnsLine_Generation_Area");

                    b.HasIndex("GenerationId", "UnsLineId")
                        .IsUnique()
                        .HasDatabaseName("UX_UnsLine_Generation_LogicalId")
                        .HasFilter("[UnsLineId] IS NOT NULL");

                    b.HasIndex("GenerationId", "UnsAreaId", "Name")
                        .IsUnique()
                        .HasDatabaseName("UX_UnsLine_Generation_AreaName");

                    b.ToTable("UnsLine", (string)null);
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNode", b =>
                {
                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", "Cluster")
                        .WithMany("Nodes")
                        .HasForeignKey("ClusterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Cluster");
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNodeCredential", b =>
                {
                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNode", "Node")
                        .WithMany("Credentials")
                        .HasForeignKey("NodeId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Node");
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNodeGenerationState", b =>
                {
                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigGeneration", "CurrentGeneration")
                        .WithMany()
                        .HasForeignKey("CurrentGenerationId")
                        .OnDelete(DeleteBehavior.Restrict);

                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNode", "Node")
                        .WithOne("GenerationState")
                        .HasForeignKey("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNodeGenerationState", "NodeId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("CurrentGeneration");

                    b.Navigation("Node");
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigGeneration", b =>
                {
                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", "Cluster")
                        .WithMany("Generations")
                        .HasForeignKey("ClusterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigGeneration", "Parent")
                        .WithMany()
                        .HasForeignKey("ParentGenerationId")
                        .OnDelete(DeleteBehavior.Restrict);

                    b.Navigation("Cluster");

                    b.Navigation("Parent");
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.Device", b =>
                {
                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigGeneration", "Generation")
                        .WithMany()
                        .HasForeignKey("GenerationId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Generation");
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.DriverInstance", b =>
                {
                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", "Cluster")
                        .WithMany()
                        .HasForeignKey("ClusterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigGeneration", "Generation")
                        .WithMany()
                        .HasForeignKey("GenerationId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Cluster");

                    b.Navigation("Generation");
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.Equipment", b =>
                {
                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigGeneration", "Generation")
                        .WithMany()
                        .HasForeignKey("GenerationId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Generation");
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.Namespace", b =>
                {
                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", "Cluster")
                        .WithMany("Namespaces")
                        .HasForeignKey("ClusterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigGeneration", "Generation")
                        .WithMany()
                        .HasForeignKey("GenerationId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Cluster");

                    b.Navigation("Generation");
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.NodeAcl", b =>
                {
                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigGeneration", "Generation")
                        .WithMany()
                        .HasForeignKey("GenerationId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Generation");
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.PollGroup", b =>
                {
                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigGeneration", "Generation")
                        .WithMany()
                        .HasForeignKey("GenerationId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Generation");
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.Tag", b =>
                {
                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigGeneration", "Generation")
                        .WithMany()
                        .HasForeignKey("GenerationId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Generation");
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.UnsArea", b =>
                {
                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", "Cluster")
                        .WithMany()
                        .HasForeignKey("ClusterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigGeneration", "Generation")
                        .WithMany()
                        .HasForeignKey("GenerationId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Cluster");

                    b.Navigation("Generation");
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.UnsLine", b =>
                {
                    b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigGeneration", "Generation")
                        .WithMany()
                        .HasForeignKey("GenerationId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Generation");
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNode", b =>
                {
                    b.Navigation("Credentials");

                    b.Navigation("GenerationState");
                });

            modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", b =>
                {
                    b.Navigation("Generations");

                    b.Navigation("Namespaces");

                    b.Navigation("Nodes");
                });
#pragma warning restore 612, 618
        }
    }
}
