// <auto-generated />
using System;
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Tiku.Infrastructure.Persistence;

#nullable disable

namespace Tiku.Infrastructure.Persistence.Migrations
{
    [DbContext(typeof(TikuDbContext))]
    [Migration("20260729053904_InitialSchema")]
    partial class InitialSchema
    {
        /// <inheritdoc />
        protected override void BuildTargetModel(ModelBuilder modelBuilder)
        {
#pragma warning disable 612, 618
            modelBuilder
                .HasAnnotation("ProductVersion", "10.0.10")
                .HasAnnotation("Relational:MaxIdentifierLength", 63);

            NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "citext");
            NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "ltree");
            NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);

            modelBuilder.Entity("MassTransit.EntityFrameworkCoreIntegration.InboxState", b =>
                {
                    b.Property<long>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("bigint")
                        .HasColumnName("id");

                    NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));

                    b.Property<DateTime?>("Consumed")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("consumed");

                    b.Property<Guid>("ConsumerId")
                        .HasColumnType("uuid")
                        .HasColumnName("consumer_id");

                    b.Property<DateTime?>("Delivered")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("delivered");

                    b.Property<DateTime?>("ExpirationTime")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("expiration_time");

                    b.Property<long?>("LastSequenceNumber")
                        .HasColumnType("bigint")
                        .HasColumnName("last_sequence_number");

                    b.Property<Guid>("LockId")
                        .HasColumnType("uuid")
                        .HasColumnName("lock_id");

                    b.Property<Guid>("MessageId")
                        .HasColumnType("uuid")
                        .HasColumnName("message_id");

                    b.Property<int>("ReceiveCount")
                        .HasColumnType("integer")
                        .HasColumnName("receive_count");

                    b.Property<DateTime>("Received")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("received");

                    b.Property<byte[]>("RowVersion")
                        .IsConcurrencyToken()
                        .ValueGeneratedOnAddOrUpdate()
                        .HasColumnType("bytea")
                        .HasColumnName("row_version");

                    b.HasKey("Id")
                        .HasName("pk_inbox_state");

                    b.HasAlternateKey("MessageId", "ConsumerId")
                        .HasName("ak_inbox_state_message_id_consumer_id");

                    b.HasIndex("Delivered")
                        .HasDatabaseName("ix_inbox_state_delivered");

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

            modelBuilder.Entity("MassTransit.EntityFrameworkCoreIntegration.OutboxMessage", b =>
                {
                    b.Property<long>("SequenceNumber")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("bigint")
                        .HasColumnName("sequence_number");

                    NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("SequenceNumber"));

                    b.Property<string>("Body")
                        .IsRequired()
                        .HasColumnType("text")
                        .HasColumnName("body");

                    b.Property<string>("ContentType")
                        .IsRequired()
                        .HasMaxLength(256)
                        .HasColumnType("character varying(256)")
                        .HasColumnName("content_type");

                    b.Property<Guid?>("ConversationId")
                        .HasColumnType("uuid")
                        .HasColumnName("conversation_id");

                    b.Property<Guid?>("CorrelationId")
                        .HasColumnType("uuid")
                        .HasColumnName("correlation_id");

                    b.Property<string>("DestinationAddress")
                        .HasMaxLength(256)
                        .HasColumnType("character varying(256)")
                        .HasColumnName("destination_address");

                    b.Property<DateTime?>("EnqueueTime")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("enqueue_time");

                    b.Property<DateTime?>("ExpirationTime")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("expiration_time");

                    b.Property<string>("FaultAddress")
                        .HasMaxLength(256)
                        .HasColumnType("character varying(256)")
                        .HasColumnName("fault_address");

                    b.Property<string>("Headers")
                        .HasColumnType("text")
                        .HasColumnName("headers");

                    b.Property<Guid?>("InboxConsumerId")
                        .HasColumnType("uuid")
                        .HasColumnName("inbox_consumer_id");

                    b.Property<Guid?>("InboxMessageId")
                        .HasColumnType("uuid")
                        .HasColumnName("inbox_message_id");

                    b.Property<Guid?>("InitiatorId")
                        .HasColumnType("uuid")
                        .HasColumnName("initiator_id");

                    b.Property<Guid>("MessageId")
                        .HasColumnType("uuid")
                        .HasColumnName("message_id");

                    b.Property<string>("MessageType")
                        .IsRequired()
                        .HasColumnType("text")
                        .HasColumnName("message_type");

                    b.Property<Guid?>("OutboxId")
                        .HasColumnType("uuid")
                        .HasColumnName("outbox_id");

                    b.Property<string>("Properties")
                        .HasColumnType("text")
                        .HasColumnName("properties");

                    b.Property<Guid?>("RequestId")
                        .HasColumnType("uuid")
                        .HasColumnName("request_id");

                    b.Property<string>("ResponseAddress")
                        .HasMaxLength(256)
                        .HasColumnType("character varying(256)")
                        .HasColumnName("response_address");

                    b.Property<DateTime>("SentTime")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("sent_time");

                    b.Property<string>("SourceAddress")
                        .HasMaxLength(256)
                        .HasColumnType("character varying(256)")
                        .HasColumnName("source_address");

                    b.HasKey("SequenceNumber")
                        .HasName("pk_outbox_message");

                    b.HasIndex("EnqueueTime")
                        .HasDatabaseName("ix_outbox_message_enqueue_time");

                    b.HasIndex("ExpirationTime")
                        .HasDatabaseName("ix_outbox_message_expiration_time");

                    b.HasIndex("OutboxId", "SequenceNumber")
                        .IsUnique()
                        .HasDatabaseName("ix_outbox_message_outbox_id_sequence_number");

                    b.HasIndex("InboxMessageId", "InboxConsumerId", "SequenceNumber")
                        .IsUnique()
                        .HasDatabaseName("ix_outbox_message_inbox_message_id_inbox_consumer_id_sequence_~");

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

            modelBuilder.Entity("MassTransit.EntityFrameworkCoreIntegration.OutboxState", b =>
                {
                    b.Property<Guid>("OutboxId")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("outbox_id");

                    b.Property<DateTime>("Created")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created");

                    b.Property<DateTime?>("Delivered")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("delivered");

                    b.Property<long?>("LastSequenceNumber")
                        .HasColumnType("bigint")
                        .HasColumnName("last_sequence_number");

                    b.Property<Guid>("LockId")
                        .HasColumnType("uuid")
                        .HasColumnName("lock_id");

                    b.Property<byte[]>("RowVersion")
                        .IsConcurrencyToken()
                        .ValueGeneratedOnAddOrUpdate()
                        .HasColumnType("bytea")
                        .HasColumnName("row_version");

                    b.HasKey("OutboxId")
                        .HasName("pk_outbox_state");

                    b.HasIndex("Created")
                        .HasDatabaseName("ix_outbox_state_created");

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

            modelBuilder.Entity("Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.DataProtectionKey", b =>
                {
                    b.Property<int>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("integer")
                        .HasColumnName("id");

                    NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));

                    b.Property<string>("FriendlyName")
                        .HasColumnType("text")
                        .HasColumnName("friendly_name");

                    b.Property<string>("Xml")
                        .HasColumnType("text")
                        .HasColumnName("xml");

                    b.HasKey("Id")
                        .HasName("pk_data_protection_keys");

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

            modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
                {
                    b.Property<int>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("integer")
                        .HasColumnName("id");

                    NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));

                    b.Property<string>("ClaimType")
                        .HasColumnType("text")
                        .HasColumnName("claim_type");

                    b.Property<string>("ClaimValue")
                        .HasColumnType("text")
                        .HasColumnName("claim_value");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_user_claims");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_user_claims_user_id");

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

            modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
                {
                    b.Property<string>("LoginProvider")
                        .HasColumnType("text")
                        .HasColumnName("login_provider");

                    b.Property<string>("ProviderKey")
                        .HasColumnType("text")
                        .HasColumnName("provider_key");

                    b.Property<string>("ProviderDisplayName")
                        .HasColumnType("text")
                        .HasColumnName("provider_display_name");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("LoginProvider", "ProviderKey")
                        .HasName("pk_user_logins");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_user_logins_user_id");

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

            modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
                {
                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.Property<string>("LoginProvider")
                        .HasColumnType("text")
                        .HasColumnName("login_provider");

                    b.Property<string>("Name")
                        .HasColumnType("text")
                        .HasColumnName("name");

                    b.Property<string>("Value")
                        .HasColumnType("text")
                        .HasColumnName("value");

                    b.HasKey("UserId", "LoginProvider", "Name")
                        .HasName("pk_user_tokens");

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

            modelBuilder.Entity("Tiku.Domain.Catalog.Category", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("CategoryType")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("category_type");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("name");

                    b.Property<Guid?>("NodeId")
                        .HasColumnType("uuid")
                        .HasColumnName("node_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid?>("SubjectId")
                        .HasColumnType("uuid")
                        .HasColumnName("subject_id");

                    b.Property<int?>("SvipQuestionLimit")
                        .HasColumnType("integer")
                        .HasColumnName("svip_question_limit");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_categories");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_categories_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_categories_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "NodeId")
                        .HasDatabaseName("ix_categories_tenant_id_node_id");

                    b.HasIndex("TenantId", "SubjectId")
                        .HasDatabaseName("ix_categories_tenant_id_subject_id");

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

            modelBuilder.Entity("Tiku.Domain.Catalog.Major", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("name");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<Guid?>("SchoolId")
                        .HasColumnType("uuid")
                        .HasColumnName("school_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("StudyTips")
                        .HasColumnType("text")
                        .HasColumnName("study_tips");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_majors");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_majors_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_majors_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_majors_tenant_id_region_id");

                    b.HasIndex("TenantId", "SchoolId")
                        .HasDatabaseName("ix_majors_tenant_id_school_id");

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

            modelBuilder.Entity("Tiku.Domain.Catalog.ModuleNode", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("LegacyModuleId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_module_id");

                    b.Property<string>("LegacyParentId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_parent_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid?>("ModuleId")
                        .HasColumnType("uuid")
                        .HasColumnName("module_id");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("name");

                    b.Property<Guid?>("ParentId")
                        .HasColumnType("uuid")
                        .HasColumnName("parent_id");

                    b.Property<string>("Path")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("path");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Type")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("type");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_module_nodes");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_module_nodes_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_module_nodes_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "ModuleId")
                        .HasDatabaseName("ix_module_nodes_tenant_id_module_id");

                    b.HasIndex("TenantId", "ParentId")
                        .HasDatabaseName("ix_module_nodes_tenant_id_parent_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_module_nodes_tenant_id_region_id");

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

            modelBuilder.Entity("Tiku.Domain.Catalog.QuestionTaxonomyAssignment", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<bool>("IsPrimary")
                        .HasColumnType("boolean")
                        .HasColumnName("is_primary");

                    b.Property<Guid>("QuestionId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_id");

                    b.Property<Guid>("TaxonomyNodeId")
                        .HasColumnType("uuid")
                        .HasColumnName("taxonomy_node_id");

                    b.Property<Guid>("TaxonomyOwnerTenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("taxonomy_owner_tenant_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.HasKey("Id")
                        .HasName("pk_question_taxonomy_assignments");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_question_taxonomy_assignments_tenant_id_id");

                    b.HasIndex("TaxonomyOwnerTenantId", "TaxonomyNodeId")
                        .HasDatabaseName("ix_question_taxonomy_assignments_taxonomy_owner_tenant_id_taxo~");

                    b.HasIndex("TenantId", "QuestionId", "TaxonomyOwnerTenantId", "TaxonomyNodeId")
                        .IsUnique()
                        .HasDatabaseName("ix_question_taxonomy_assignments_tenant_id_question_id_taxonom~");

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

            modelBuilder.Entity("Tiku.Domain.Catalog.Region", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Code")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("code");

                    b.Property<JsonElement>("Config")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("config")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("FullName")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("full_name");

                    b.Property<string>("Icon")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("icon");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<bool>("IsHot")
                        .HasColumnType("boolean")
                        .HasColumnName("is_hot");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<string>("Pinyin")
                        .HasMaxLength(255)
                        .HasColumnType("character varying(255)")
                        .HasColumnName("pinyin");

                    b.Property<string>("ShortName")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("short_name");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_regions");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_regions_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_regions_tenant_id_legacy_id");

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

            modelBuilder.Entity("Tiku.Domain.Catalog.RegionModule", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Color")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("color");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<string>("Icon")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("icon");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<bool>("IsPrimarySchoolModule")
                        .HasColumnType("boolean")
                        .HasColumnName("is_primary_school_module");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<string>("Route")
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("route");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("TextColor")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("text_color");

                    b.Property<string>("Type")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("type");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_region_modules");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_region_modules_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_region_modules_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_region_modules_tenant_id_region_id");

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

            modelBuilder.Entity("Tiku.Domain.Catalog.School", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid?>("ModuleId")
                        .HasColumnType("uuid")
                        .HasColumnName("module_id");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("name");

                    b.Property<string>("ProfessionalExamDate")
                        .HasMaxLength(255)
                        .HasColumnType("character varying(255)")
                        .HasColumnName("professional_exam_date");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_schools");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_schools_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_schools_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "ModuleId")
                        .HasDatabaseName("ix_schools_tenant_id_module_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_schools_tenant_id_region_id");

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

            modelBuilder.Entity("Tiku.Domain.Catalog.ScorelineField", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("description");

                    b.Property<string>("FieldKey")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("field_key");

                    b.Property<string>("FieldName")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("field_name");

                    b.Property<string>("FieldType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("field_type");

                    b.Property<bool>("IsFilter")
                        .HasColumnType("boolean")
                        .HasColumnName("is_filter");

                    b.Property<bool>("IsRequired")
                        .HasColumnType("boolean")
                        .HasColumnName("is_required");

                    b.Property<bool>("IsTrend")
                        .HasColumnType("boolean")
                        .HasColumnName("is_trend");

                    b.Property<bool>("IsVisible")
                        .HasColumnType("boolean")
                        .HasColumnName("is_visible");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Options")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("options")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<string>("Placeholder")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("placeholder");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Unit")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("unit");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_scoreline_fields");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_scoreline_fields_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_scoreline_fields_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RegionId", "FieldKey")
                        .IsUnique()
                        .HasDatabaseName("ix_scoreline_fields_tenant_id_region_id_field_key");

                    b.HasIndex("TenantId", "RegionId", "IsFilter", "SortOrder")
                        .HasDatabaseName("ix_scoreline_fields_tenant_id_region_id_is_filter_sort_order");

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

            modelBuilder.Entity("Tiku.Domain.Catalog.ScorelineRecord", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("FieldValues")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("field_values")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<Guid?>("MajorId")
                        .HasColumnType("uuid")
                        .HasColumnName("major_id");

                    b.Property<string>("MajorName")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("major_name");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<Guid?>("SchoolId")
                        .HasColumnType("uuid")
                        .HasColumnName("school_id");

                    b.Property<string>("SchoolName")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("school_name");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int>("Year")
                        .HasColumnType("integer")
                        .HasColumnName("year");

                    b.HasKey("Id")
                        .HasName("pk_scoreline_records");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_scoreline_records_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_scoreline_records_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "MajorId")
                        .HasDatabaseName("ix_scoreline_records_tenant_id_major_id");

                    b.HasIndex("TenantId", "SchoolId")
                        .HasDatabaseName("ix_scoreline_records_tenant_id_school_id");

                    b.HasIndex("TenantId", "Year")
                        .HasDatabaseName("ix_scoreline_records_tenant_id_year");

                    b.HasIndex("TenantId", "RegionId", "SchoolId", "MajorId", "Year")
                        .HasDatabaseName("ix_scoreline_records_tenant_id_region_id_school_id_major_id_ye~");

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

            modelBuilder.Entity("Tiku.Domain.Catalog.Subject", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<string>("Icon")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("icon");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<Guid?>("MajorId")
                        .HasColumnType("uuid")
                        .HasColumnName("major_id");

                    b.Property<JsonElement>("MajorLegacyIds")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("major_legacy_ids")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<Guid?>("ModuleId")
                        .HasColumnType("uuid")
                        .HasColumnName("module_id");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("name");

                    b.Property<Guid?>("NodeId")
                        .HasColumnType("uuid")
                        .HasColumnName("node_id");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<Guid?>("SchoolId")
                        .HasColumnType("uuid")
                        .HasColumnName("school_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<JsonElement>("Stats")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("stats")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Type")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("type");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_subjects");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_subjects_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_subjects_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "MajorId")
                        .HasDatabaseName("ix_subjects_tenant_id_major_id");

                    b.HasIndex("TenantId", "ModuleId")
                        .HasDatabaseName("ix_subjects_tenant_id_module_id");

                    b.HasIndex("TenantId", "NodeId")
                        .HasDatabaseName("ix_subjects_tenant_id_node_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_subjects_tenant_id_region_id");

                    b.HasIndex("TenantId", "SchoolId")
                        .HasDatabaseName("ix_subjects_tenant_id_school_id");

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

            modelBuilder.Entity("Tiku.Domain.Catalog.TaxonomyNode", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Code")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("code");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int>("Depth")
                        .HasColumnType("integer")
                        .HasColumnName("depth");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("name");

                    b.Property<string>("NodeType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("node_type");

                    b.Property<Guid?>("ParentId")
                        .HasColumnType("uuid")
                        .HasColumnName("parent_id");

                    b.Property<Guid?>("ParentOwnerTenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("parent_owner_tenant_id");

                    b.Property<string>("Path")
                        .HasColumnType("ltree")
                        .HasColumnName("path");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_taxonomy_nodes");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_taxonomy_nodes_tenant_id_id");

                    b.HasIndex("ParentOwnerTenantId", "ParentId")
                        .HasDatabaseName("ix_taxonomy_nodes_parent_owner_tenant_id_parent_id");

                    b.HasIndex("TenantId", "Code")
                        .IsUnique()
                        .HasDatabaseName("ix_taxonomy_nodes_tenant_id_code");

                    b.ToTable("taxonomy_nodes", null, t =>
                        {
                            t.HasCheckConstraint("ck_taxonomy_nodes_parent_pair", "(parent_owner_tenant_id is null) = (parent_id is null)");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.ActivationCode", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid?>("AgentUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("agent_user_id");

                    b.Property<Guid?>("BatchId")
                        .HasColumnType("uuid")
                        .HasColumnName("batch_id");

                    b.Property<string>("Code")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("citext")
                        .HasColumnName("code");

                    b.Property<string>("CouponCode")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("coupon_code");

                    b.Property<Guid?>("CouponRedemptionId")
                        .HasColumnType("uuid")
                        .HasColumnName("coupon_redemption_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int>("Days")
                        .HasColumnType("integer")
                        .HasColumnName("days");

                    b.Property<bool>("IsUsed")
                        .HasColumnType("boolean")
                        .HasColumnName("is_used");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("Remark")
                        .HasColumnType("text")
                        .HasColumnName("remark");

                    b.Property<string>("SaleType")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("sale_type");

                    b.Property<string>("SoldTo")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("sold_to");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<int?>("UnitPriceCents")
                        .HasColumnType("integer")
                        .HasColumnName("unit_price_cents");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset?>("UsedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("used_at");

                    b.Property<Guid?>("UsedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("used_by");

                    b.Property<Guid?>("UsedRegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("used_region_id");

                    b.HasKey("Id")
                        .HasName("pk_activation_codes");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_activation_codes_tenant_id_id");

                    b.HasIndex("AgentUserId")
                        .HasDatabaseName("ix_activation_codes_agent_user_id");

                    b.HasIndex("UsedBy")
                        .HasDatabaseName("ix_activation_codes_used_by");

                    b.HasIndex("TenantId", "BatchId")
                        .HasDatabaseName("ix_activation_codes_tenant_id_batch_id");

                    b.HasIndex("TenantId", "Code")
                        .IsUnique()
                        .HasDatabaseName("ix_activation_codes_tenant_id_code");

                    b.HasIndex("TenantId", "CouponRedemptionId")
                        .HasDatabaseName("ix_activation_codes_tenant_id_coupon_redemption_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_activation_codes_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "UsedRegionId")
                        .HasDatabaseName("ix_activation_codes_tenant_id_used_region_id");

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

            modelBuilder.Entity("Tiku.Domain.Commerce.CodeBatch", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("CampaignName")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("campaign_name");

                    b.Property<string>("Channel")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("channel");

                    b.Property<decimal?>("CommissionRate")
                        .HasPrecision(6, 4)
                        .HasColumnType("numeric(6,4)")
                        .HasColumnName("commission_rate");

                    b.Property<int>("CostPriceCents")
                        .HasColumnType("integer")
                        .HasColumnName("cost_price_cents");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<int?>("Days")
                        .HasColumnType("integer")
                        .HasColumnName("days");

                    b.Property<int>("DefaultUnitPriceCents")
                        .HasColumnType("integer")
                        .HasColumnName("default_unit_price_cents");

                    b.Property<DateTimeOffset?>("IssuedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("issued_at");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("LegacyRegionId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_region_id");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<string>("Remark")
                        .HasColumnType("text")
                        .HasColumnName("remark");

                    b.Property<string>("SaleType")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("sale_type");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<int>("TotalCount")
                        .HasColumnType("integer")
                        .HasColumnName("total_count");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_code_batches");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_code_batches_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_code_batches_tenant_id_legacy_id");

                    b.ToTable("code_batches", null, t =>
                        {
                            t.HasCheckConstraint("ck_code_batches_amounts", "default_unit_price_cents >= 0 and cost_price_cents >= 0");

                            t.HasCheckConstraint("ck_code_batches_counts", "total_count >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceAdjustmentVoucher", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("AmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("amount_cents");

                    b.Property<Guid?>("BatchId")
                        .HasColumnType("uuid")
                        .HasColumnName("batch_id");

                    b.Property<DateTimeOffset?>("ClosedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("closed_at");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<string>("Currency")
                        .IsRequired()
                        .HasMaxLength(10)
                        .HasColumnType("character varying(10)")
                        .HasColumnName("currency");

                    b.Property<string>("Direction")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("direction");

                    b.Property<Guid?>("IssueId")
                        .HasColumnType("uuid")
                        .HasColumnName("issue_id");

                    b.Property<Guid?>("ItemId")
                        .HasColumnType("uuid")
                        .HasColumnName("item_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid?>("OrderId")
                        .HasColumnType("uuid")
                        .HasColumnName("order_id");

                    b.Property<Guid?>("PaymentId")
                        .HasColumnType("uuid")
                        .HasColumnName("payment_id");

                    b.Property<string>("ProofAssetKey")
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("proof_asset_key");

                    b.Property<string>("Reason")
                        .IsRequired()
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("reason");

                    b.Property<Guid?>("RefundRequestId")
                        .HasColumnType("uuid")
                        .HasColumnName("refund_request_id");

                    b.Property<DateTimeOffset?>("ReviewedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("reviewed_at");

                    b.Property<Guid?>("ReviewedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("reviewed_by");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("VoucherNo")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("voucher_no");

                    b.HasKey("Id")
                        .HasName("pk_commerce_adjustment_vouchers");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_commerce_adjustment_vouchers_tenant_id_id");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_commerce_adjustment_vouchers_created_by");

                    b.HasIndex("ReviewedBy")
                        .HasDatabaseName("ix_commerce_adjustment_vouchers_reviewed_by");

                    b.HasIndex("TenantId", "BatchId")
                        .HasDatabaseName("ix_commerce_adjustment_vouchers_tenant_id_batch_id");

                    b.HasIndex("TenantId", "ItemId")
                        .HasDatabaseName("ix_commerce_adjustment_vouchers_tenant_id_item_id");

                    b.HasIndex("TenantId", "OrderId")
                        .HasDatabaseName("ix_commerce_adjustment_vouchers_tenant_id_order_id");

                    b.HasIndex("TenantId", "PaymentId")
                        .HasDatabaseName("ix_commerce_adjustment_vouchers_tenant_id_payment_id");

                    b.HasIndex("TenantId", "RefundRequestId")
                        .HasDatabaseName("ix_commerce_adjustment_vouchers_tenant_id_refund_request_id");

                    b.HasIndex("TenantId", "VoucherNo")
                        .IsUnique()
                        .HasDatabaseName("ix_commerce_adjustment_vouchers_tenant_id_voucher_no");

                    b.HasIndex("TenantId", "IssueId", "CreatedAt")
                        .HasDatabaseName("ix_commerce_adjustment_vouchers_tenant_id_issue_id_created_at");

                    b.HasIndex("TenantId", "Status", "CreatedAt")
                        .HasDatabaseName("ix_commerce_adjustment_vouchers_tenant_id_status_created_at");

                    b.ToTable("commerce_adjustment_vouchers", null, t =>
                        {
                            t.HasCheckConstraint("ck_commerce_adjustment_vouchers_amount", "amount_cents > 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceAdjustmentVoucherEvent", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid?>("ActorUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("actor_user_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("Details")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("details")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("FromStatus")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("from_status");

                    b.Property<string>("Note")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("note");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("ToStatus")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("to_status");

                    b.Property<Guid>("VoucherId")
                        .HasColumnType("uuid")
                        .HasColumnName("voucher_id");

                    b.HasKey("Id")
                        .HasName("pk_commerce_adjustment_voucher_events");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_commerce_adjustment_voucher_events_tenant_id_id");

                    b.HasIndex("ActorUserId")
                        .HasDatabaseName("ix_commerce_adjustment_voucher_events_actor_user_id");

                    b.HasIndex("TenantId", "VoucherId", "CreatedAt")
                        .HasDatabaseName("ix_commerce_adjustment_voucher_events_tenant_id_voucher_id_cre~");

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

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceReconciliationBatch", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("AmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("amount_cents");

                    b.Property<DateOnly>("BillDate")
                        .HasColumnType("date")
                        .HasColumnName("bill_date");

                    b.Property<string>("BillType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("bill_type");

                    b.Property<DateTimeOffset?>("CompletedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("completed_at");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<int>("DuplicateCount")
                        .HasColumnType("integer")
                        .HasColumnName("duplicate_count");

                    b.Property<string>("Error")
                        .HasColumnType("text")
                        .HasColumnName("error");

                    b.Property<int>("FeeCents")
                        .HasColumnType("integer")
                        .HasColumnName("fee_cents");

                    b.Property<int>("IgnoredCount")
                        .HasColumnType("integer")
                        .HasColumnName("ignored_count");

                    b.Property<int>("MatchedCount")
                        .HasColumnType("integer")
                        .HasColumnName("matched_count");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("MismatchCount")
                        .HasColumnType("integer")
                        .HasColumnName("mismatch_count");

                    b.Property<int>("MissingLocalCount")
                        .HasColumnType("integer")
                        .HasColumnName("missing_local_count");

                    b.Property<int>("MissingProviderCount")
                        .HasColumnType("integer")
                        .HasColumnName("missing_provider_count");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("provider");

                    b.Property<int>("RefundAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("refund_amount_cents");

                    b.Property<string>("Source")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("source");

                    b.Property<string>("SourceHash")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("source_hash");

                    b.Property<string>("SourceName")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("source_name");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<int>("TotalCount")
                        .HasColumnType("integer")
                        .HasColumnName("total_count");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_commerce_reconciliation_batches");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_commerce_reconciliation_batches_tenant_id_id");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_commerce_reconciliation_batches_created_by");

                    b.HasIndex("TenantId", "Status", "CreatedAt")
                        .HasDatabaseName("ix_commerce_reconciliation_batches_tenant_id_status_created_at");

                    b.HasIndex("TenantId", "Provider", "BillDate", "CreatedAt")
                        .HasDatabaseName("ix_commerce_reconciliation_batches_tenant_id_provider_bill_dat~");

                    b.ToTable("commerce_reconciliation_batches", null, t =>
                        {
                            t.HasCheckConstraint("ck_commerce_reconciliation_batches_amounts", "amount_cents >= 0 and refund_amount_cents >= 0");

                            t.HasCheckConstraint("ck_commerce_reconciliation_batches_counts", "total_count >= 0 and matched_count >= 0 and mismatch_count >= 0 and missing_local_count >= 0 and missing_provider_count >= 0 and duplicate_count >= 0 and ignored_count >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceReconciliationIssue", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("AmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("amount_cents");

                    b.Property<Guid?>("AssignedTo")
                        .HasColumnType("uuid")
                        .HasColumnName("assigned_to");

                    b.Property<Guid?>("BatchId")
                        .HasColumnType("uuid")
                        .HasColumnName("batch_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<DateTimeOffset?>("DueAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("due_at");

                    b.Property<string>("IssueCode")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("issue_code");

                    b.Property<string>("IssueNo")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("issue_no");

                    b.Property<Guid?>("ItemId")
                        .HasColumnType("uuid")
                        .HasColumnName("item_id");

                    b.Property<string>("MatchStatus")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("match_status");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid?>("OrderId")
                        .HasColumnType("uuid")
                        .HasColumnName("order_id");

                    b.Property<string>("OrderNo")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("order_no");

                    b.Property<Guid?>("PaymentId")
                        .HasColumnType("uuid")
                        .HasColumnName("payment_id");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("provider");

                    b.Property<string>("ProviderRefundNo")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("provider_refund_no");

                    b.Property<string>("ProviderTradeNo")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("provider_trade_no");

                    b.Property<int>("RefundAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("refund_amount_cents");

                    b.Property<string>("RefundNo")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("refund_no");

                    b.Property<Guid?>("RefundRequestId")
                        .HasColumnType("uuid")
                        .HasColumnName("refund_request_id");

                    b.Property<string>("ResolutionNote")
                        .HasColumnType("text")
                        .HasColumnName("resolution_note");

                    b.Property<string>("ResolutionType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("resolution_type");

                    b.Property<DateTimeOffset?>("ResolvedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("resolved_at");

                    b.Property<Guid?>("ResolvedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("resolved_by");

                    b.Property<string>("Severity")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("severity");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<string>("Summary")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("summary");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("TransactionType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("transaction_type");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_commerce_reconciliation_issues");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_commerce_reconciliation_issues_tenant_id_id");

                    b.HasIndex("AssignedTo")
                        .HasDatabaseName("ix_commerce_reconciliation_issues_assigned_to");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_commerce_reconciliation_issues_created_by");

                    b.HasIndex("ResolvedBy")
                        .HasDatabaseName("ix_commerce_reconciliation_issues_resolved_by");

                    b.HasIndex("TenantId", "IssueNo")
                        .IsUnique()
                        .HasDatabaseName("ix_commerce_reconciliation_issues_tenant_id_issue_no");

                    b.HasIndex("TenantId", "ItemId")
                        .IsUnique()
                        .HasDatabaseName("ix_commerce_reconciliation_issues_tenant_id_item_id")
                        .HasFilter("item_id is not null and status in ('open', 'investigating', 'escalated')");

                    b.HasIndex("TenantId", "OrderId")
                        .HasDatabaseName("ix_commerce_reconciliation_issues_tenant_id_order_id");

                    b.HasIndex("TenantId", "RefundRequestId")
                        .HasDatabaseName("ix_commerce_reconciliation_issues_tenant_id_refund_request_id");

                    b.HasIndex("TenantId", "OrderNo", "CreatedAt")
                        .HasDatabaseName("ix_commerce_reconciliation_issues_tenant_id_order_no_created_at");

                    b.HasIndex("TenantId", "PaymentId", "CreatedAt")
                        .HasDatabaseName("ix_commerce_reconciliation_issues_tenant_id_payment_id_created~");

                    b.HasIndex("TenantId", "AssignedTo", "Status", "DueAt")
                        .HasDatabaseName("ix_commerce_reconciliation_issues_tenant_id_assigned_to_status~");

                    b.HasIndex("TenantId", "BatchId", "Status", "CreatedAt")
                        .HasDatabaseName("ix_commerce_reconciliation_issues_tenant_id_batch_id_status_cr~");

                    b.HasIndex("TenantId", "Status", "Severity", "CreatedAt")
                        .HasDatabaseName("ix_commerce_reconciliation_issues_tenant_id_status_severity_cr~");

                    b.ToTable("commerce_reconciliation_issues", null, t =>
                        {
                            t.HasCheckConstraint("ck_commerce_reconciliation_issues_amounts", "amount_cents >= 0 and refund_amount_cents >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceReconciliationIssueEvent", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid?>("ActorUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("actor_user_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("Details")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("details")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("EventType")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("event_type");

                    b.Property<string>("FromStatus")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("from_status");

                    b.Property<Guid>("IssueId")
                        .HasColumnType("uuid")
                        .HasColumnName("issue_id");

                    b.Property<string>("Note")
                        .HasColumnType("text")
                        .HasColumnName("note");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("ToStatus")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("to_status");

                    b.HasKey("Id")
                        .HasName("pk_commerce_reconciliation_issue_events");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_commerce_reconciliation_issue_events_tenant_id_id");

                    b.HasIndex("ActorUserId")
                        .HasDatabaseName("ix_commerce_reconciliation_issue_events_actor_user_id");

                    b.HasIndex("TenantId", "IssueId", "CreatedAt")
                        .HasDatabaseName("ix_commerce_reconciliation_issue_events_tenant_id_issue_id_cre~");

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

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceReconciliationItem", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("AmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("amount_cents");

                    b.Property<Guid>("BatchId")
                        .HasColumnType("uuid")
                        .HasColumnName("batch_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("Details")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("details")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("FeeCents")
                        .HasColumnType("integer")
                        .HasColumnName("fee_cents");

                    b.Property<string>("IssueCode")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("issue_code");

                    b.Property<string>("LocalStatus")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("local_status");

                    b.Property<string>("MatchStatus")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("match_status");

                    b.Property<Guid?>("OrderId")
                        .HasColumnType("uuid")
                        .HasColumnName("order_id");

                    b.Property<string>("OrderNo")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("order_no");

                    b.Property<DateTimeOffset?>("PaidAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("paid_at");

                    b.Property<Guid?>("PaymentId")
                        .HasColumnType("uuid")
                        .HasColumnName("payment_id");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("provider");

                    b.Property<string>("ProviderRefundNo")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("provider_refund_no");

                    b.Property<string>("ProviderStatus")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("provider_status");

                    b.Property<string>("ProviderTradeNo")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("provider_trade_no");

                    b.Property<int>("RefundAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("refund_amount_cents");

                    b.Property<string>("RefundNo")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("refund_no");

                    b.Property<Guid?>("RefundRequestId")
                        .HasColumnType("uuid")
                        .HasColumnName("refund_request_id");

                    b.Property<DateTimeOffset?>("RefundedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("refunded_at");

                    b.Property<int>("RowNo")
                        .HasColumnType("integer")
                        .HasColumnName("row_no");

                    b.Property<string>("Severity")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("severity");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("TransactionType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("transaction_type");

                    b.HasKey("Id")
                        .HasName("pk_commerce_reconciliation_items");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_commerce_reconciliation_items_tenant_id_id");

                    b.HasIndex("TenantId", "OrderId")
                        .HasDatabaseName("ix_commerce_reconciliation_items_tenant_id_order_id");

                    b.HasIndex("TenantId", "PaymentId")
                        .HasDatabaseName("ix_commerce_reconciliation_items_tenant_id_payment_id");

                    b.HasIndex("TenantId", "RefundRequestId")
                        .HasDatabaseName("ix_commerce_reconciliation_items_tenant_id_refund_request_id");

                    b.HasIndex("TenantId", "BatchId", "RowNo")
                        .IsUnique()
                        .HasDatabaseName("ix_commerce_reconciliation_items_tenant_id_batch_id_row_no");

                    b.HasIndex("TenantId", "OrderNo", "CreatedAt")
                        .HasDatabaseName("ix_commerce_reconciliation_items_tenant_id_order_no_created_at");

                    b.HasIndex("TenantId", "BatchId", "MatchStatus", "RowNo")
                        .HasDatabaseName("ix_commerce_reconciliation_items_tenant_id_batch_id_match_stat~");

                    b.HasIndex("TenantId", "Provider", "ProviderTradeNo", "CreatedAt")
                        .HasDatabaseName("ix_commerce_reconciliation_items_tenant_id_provider_provider_t~");

                    b.HasIndex("TenantId", "RefundNo", "ProviderRefundNo", "CreatedAt")
                        .HasDatabaseName("ix_commerce_reconciliation_items_tenant_id_refund_no_provider_~");

                    b.ToTable("commerce_reconciliation_items", null, t =>
                        {
                            t.HasCheckConstraint("ck_commerce_reconciliation_items_amounts", "amount_cents >= 0 and refund_amount_cents >= 0");

                            t.HasCheckConstraint("ck_commerce_reconciliation_items_row", "row_no > 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceRefundEvent", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid?>("ActorUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("actor_user_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("Details")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("details")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("EventType")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("event_type");

                    b.Property<string>("FromStatus")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("from_status");

                    b.Property<Guid>("RefundRequestId")
                        .HasColumnType("uuid")
                        .HasColumnName("refund_request_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("ToStatus")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("to_status");

                    b.HasKey("Id")
                        .HasName("pk_commerce_refund_events");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_commerce_refund_events_tenant_id_id");

                    b.HasIndex("ActorUserId")
                        .HasDatabaseName("ix_commerce_refund_events_actor_user_id");

                    b.HasIndex("TenantId", "RefundRequestId", "CreatedAt")
                        .HasDatabaseName("ix_commerce_refund_events_tenant_id_refund_request_id_created_~");

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

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceRefundRequest", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("AmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("amount_cents");

                    b.Property<DateTimeOffset?>("CancelledAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("cancelled_at");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("EntitlementAction")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("entitlement_action");

                    b.Property<DateTimeOffset?>("FailedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("failed_at");

                    b.Property<string>("FailureReason")
                        .HasColumnType("text")
                        .HasColumnName("failure_reason");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid>("OrderId")
                        .HasColumnType("uuid")
                        .HasColumnName("order_id");

                    b.Property<Guid?>("PaymentId")
                        .HasColumnType("uuid")
                        .HasColumnName("payment_id");

                    b.Property<DateTimeOffset?>("ProcessedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("processed_at");

                    b.Property<Guid?>("ProcessedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("processed_by");

                    b.Property<string>("Provider")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("provider");

                    b.Property<string>("ProviderRefundNo")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("provider_refund_no");

                    b.Property<string>("Reason")
                        .HasColumnType("text")
                        .HasColumnName("reason");

                    b.Property<string>("RefundNo")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("refund_no");

                    b.Property<DateTimeOffset>("RequestedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("requested_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("RequestedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("requested_by");

                    b.Property<DateTimeOffset?>("ReviewedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("reviewed_at");

                    b.Property<Guid?>("ReviewedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("reviewed_by");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<DateTimeOffset?>("SucceededAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("succeeded_at");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_commerce_refund_requests");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_commerce_refund_requests_tenant_id_id");

                    b.HasIndex("ProcessedBy")
                        .HasDatabaseName("ix_commerce_refund_requests_processed_by");

                    b.HasIndex("RequestedBy")
                        .HasDatabaseName("ix_commerce_refund_requests_requested_by");

                    b.HasIndex("ReviewedBy")
                        .HasDatabaseName("ix_commerce_refund_requests_reviewed_by");

                    b.HasIndex("TenantId", "PaymentId")
                        .HasDatabaseName("ix_commerce_refund_requests_tenant_id_payment_id");

                    b.HasIndex("TenantId", "RefundNo")
                        .IsUnique()
                        .HasDatabaseName("ix_commerce_refund_requests_tenant_id_refund_no");

                    b.HasIndex("TenantId", "OrderId", "CreatedAt")
                        .HasDatabaseName("ix_commerce_refund_requests_tenant_id_order_id_created_at");

                    b.HasIndex("TenantId", "Status", "CreatedAt")
                        .HasDatabaseName("ix_commerce_refund_requests_tenant_id_status_created_at");

                    b.ToTable("commerce_refund_requests", null, t =>
                        {
                            t.HasCheckConstraint("ck_commerce_refund_requests_amount", "amount_cents > 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.Coupon", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Code")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("citext")
                        .HasColumnName("code");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("DiscountType")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("discount_type");

                    b.Property<decimal?>("DiscountValue")
                        .HasPrecision(10, 2)
                        .HasColumnType("numeric(10,2)")
                        .HasColumnName("discount_value");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<int?>("MaxUses")
                        .HasColumnType("integer")
                        .HasColumnName("max_uses");

                    b.Property<Guid?>("PlanId")
                        .HasColumnType("uuid")
                        .HasColumnName("plan_id");

                    b.Property<string>("Remark")
                        .HasColumnType("text")
                        .HasColumnName("remark");

                    b.Property<string>("Source")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("source");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int>("UsedCount")
                        .HasColumnType("integer")
                        .HasColumnName("used_count");

                    b.Property<DateTimeOffset?>("ValidFrom")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("valid_from");

                    b.Property<DateTimeOffset?>("ValidTo")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("valid_to");

                    b.HasKey("Id")
                        .HasName("pk_coupons");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_coupons_tenant_id_id");

                    b.HasIndex("TenantId", "Code")
                        .IsUnique()
                        .HasDatabaseName("ix_coupons_tenant_id_code");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_coupons_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "PlanId")
                        .HasDatabaseName("ix_coupons_tenant_id_plan_id");

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

            modelBuilder.Entity("Tiku.Domain.Commerce.CouponRedemption", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset?>("ClaimedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("claimed_at");

                    b.Property<string>("CouponCode")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("coupon_code");

                    b.Property<Guid?>("CouponId")
                        .HasColumnType("uuid")
                        .HasColumnName("coupon_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int?>("DiscountAppliedCents")
                        .HasColumnType("integer")
                        .HasColumnName("discount_applied_cents");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<Guid?>("OrderId")
                        .HasColumnType("uuid")
                        .HasColumnName("order_id");

                    b.Property<Guid?>("PlanId")
                        .HasColumnType("uuid")
                        .HasColumnName("plan_id");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<string>("Remark")
                        .HasColumnType("text")
                        .HasColumnName("remark");

                    b.Property<string>("Source")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("source");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset?>("UsedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("used_at");

                    b.Property<Guid?>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_coupon_redemptions");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_coupon_redemptions_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_coupon_redemptions_user_id");

                    b.HasIndex("TenantId", "CouponId")
                        .HasDatabaseName("ix_coupon_redemptions_tenant_id_coupon_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_coupon_redemptions_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "PlanId")
                        .HasDatabaseName("ix_coupon_redemptions_tenant_id_plan_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_coupon_redemptions_tenant_id_region_id");

                    b.HasIndex("TenantId", "OrderId", "UserId")
                        .HasDatabaseName("ix_coupon_redemptions_tenant_id_order_id_user_id")
                        .HasFilter("order_id is not null");

                    b.HasIndex("TenantId", "UserId", "CouponId")
                        .IsUnique()
                        .HasDatabaseName("ix_coupon_redemptions_tenant_id_user_id_coupon_id")
                        .HasFilter("coupon_id is not null");

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

            modelBuilder.Entity("Tiku.Domain.Commerce.Entitlement", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("EntitlementType")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("entitlement_type");

                    b.Property<DateTimeOffset?>("ExpiresAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("expires_at");

                    b.Property<string>("LegacySourceId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_source_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset?>("RevokedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("revoked_at");

                    b.Property<Guid?>("RevokedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("revoked_by");

                    b.Property<string>("RevokedReason")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("revoked_reason");

                    b.Property<Guid?>("ScopeId")
                        .HasColumnType("uuid")
                        .HasColumnName("scope_id");

                    b.Property<string>("ScopeType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("scope_type");

                    b.Property<Guid?>("SourceId")
                        .HasColumnType("uuid")
                        .HasColumnName("source_id");

                    b.Property<string>("SourceType")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("source_type");

                    b.Property<DateTimeOffset>("StartsAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("starts_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_entitlements");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_entitlements_tenant_id_id");

                    b.HasIndex("RevokedBy")
                        .HasDatabaseName("ix_entitlements_revoked_by");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_entitlements_user_id");

                    b.HasIndex("TenantId", "UserId", "Status", "ExpiresAt")
                        .HasDatabaseName("ix_entitlements_tenant_id_user_id_status_expires_at");

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

            modelBuilder.Entity("Tiku.Domain.Commerce.Order", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("AmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("amount_cents");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int?>("Days")
                        .HasColumnType("integer")
                        .HasColumnName("days");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("LegacyPlanId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_plan_id");

                    b.Property<string>("LegacyRegionId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_region_id");

                    b.Property<string>("LegacyUserId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_user_id");

                    b.Property<string>("OrderNo")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("order_no");

                    b.Property<DateTimeOffset?>("PaidAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("paid_at");

                    b.Property<string>("PayMethod")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("pay_method");

                    b.Property<string>("PayProvider")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("pay_provider");

                    b.Property<Guid?>("PlanId")
                        .HasColumnType("uuid")
                        .HasColumnName("plan_id");

                    b.Property<string>("ProductName")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("product_name");

                    b.Property<string>("ProductType")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("product_type");

                    b.Property<JsonElement>("RawPayload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("raw_payload")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("RefundedAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("refunded_amount_cents");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("TradeNo")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("trade_no");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_orders");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_orders_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_orders_user_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_orders_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "OrderNo")
                        .IsUnique()
                        .HasDatabaseName("ix_orders_tenant_id_order_no");

                    b.HasIndex("TenantId", "PlanId")
                        .HasDatabaseName("ix_orders_tenant_id_plan_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_orders_tenant_id_region_id");

                    b.HasIndex("TenantId", "UserId", "CreatedAt")
                        .HasDatabaseName("ix_orders_tenant_id_user_id_created_at");

                    b.ToTable("orders", null, t =>
                        {
                            t.HasCheckConstraint("ck_orders_amount", "amount_cents >= 0");

                            t.HasCheckConstraint("ck_orders_refunded_amount", "refunded_amount_cents >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.OrderItem", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("ItemId")
                        .HasColumnType("uuid")
                        .HasColumnName("item_id");

                    b.Property<string>("ItemType")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("item_type");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("name");

                    b.Property<Guid>("OrderId")
                        .HasColumnType("uuid")
                        .HasColumnName("order_id");

                    b.Property<int>("Quantity")
                        .HasColumnType("integer")
                        .HasColumnName("quantity");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<int>("TotalAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("total_amount_cents");

                    b.Property<int>("UnitAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("unit_amount_cents");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_order_items");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_order_items_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_order_items_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "OrderId")
                        .HasDatabaseName("ix_order_items_tenant_id_order_id");

                    b.ToTable("order_items", null, t =>
                        {
                            t.HasCheckConstraint("ck_order_items_amounts", "unit_amount_cents >= 0 and total_amount_cents >= 0");

                            t.HasCheckConstraint("ck_order_items_quantity", "quantity > 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.Payment", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("AmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("amount_cents");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("LegacyOrderId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_order_id");

                    b.Property<string>("Method")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("method");

                    b.Property<Guid>("OrderId")
                        .HasColumnType("uuid")
                        .HasColumnName("order_id");

                    b.Property<DateTimeOffset?>("PaidAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("paid_at");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("provider");

                    b.Property<string>("ProviderTradeNo")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("provider_trade_no");

                    b.Property<JsonElement>("RawPayload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("raw_payload")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("RefundedAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("refunded_amount_cents");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_payments");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_payments_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_payments_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "OrderId", "UpdatedAt")
                        .HasDatabaseName("ix_payments_tenant_id_order_id_updated_at");

                    b.HasIndex("TenantId", "Provider", "ProviderTradeNo")
                        .IsUnique()
                        .HasDatabaseName("ix_payments_tenant_id_provider_provider_trade_no")
                        .HasFilter("provider_trade_no is not null");

                    b.ToTable("payments", null, t =>
                        {
                            t.HasCheckConstraint("ck_payments_amount", "amount_cents >= 0");

                            t.HasCheckConstraint("ck_payments_refunded_amount", "refunded_amount_cents >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.PaymentEvent", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Error")
                        .HasColumnType("text")
                        .HasColumnName("error");

                    b.Property<string>("EventId")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("event_id");

                    b.Property<string>("EventType")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("event_type");

                    b.Property<JsonElement>("Payload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("payload")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid?>("PaymentId")
                        .HasColumnType("uuid")
                        .HasColumnName("payment_id");

                    b.Property<DateTimeOffset?>("ProcessedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("processed_at");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("provider");

                    b.Property<bool?>("SignatureValid")
                        .HasColumnType("boolean")
                        .HasColumnName("signature_valid");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.HasKey("Id")
                        .HasName("pk_payment_events");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_payment_events_tenant_id_id");

                    b.HasIndex("TenantId", "PaymentId")
                        .HasDatabaseName("ix_payment_events_tenant_id_payment_id");

                    b.HasIndex("TenantId", "Provider", "EventId")
                        .IsUnique()
                        .HasDatabaseName("ix_payment_events_tenant_id_provider_event_id");

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

            modelBuilder.Entity("Tiku.Domain.Commerce.PointActivityClaim", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("ClaimedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("claimed_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("Points")
                        .HasColumnType("integer")
                        .HasColumnName("points");

                    b.Property<Guid?>("SourceId")
                        .HasColumnType("uuid")
                        .HasColumnName("source_id");

                    b.Property<string>("SourceType")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("source_type");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TaskId")
                        .HasColumnType("uuid")
                        .HasColumnName("task_id");

                    b.Property<string>("TaskKey")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("citext")
                        .HasColumnName("task_key");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_point_activity_claims");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_point_activity_claims_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_point_activity_claims_user_id");

                    b.HasIndex("TenantId", "TaskId")
                        .HasDatabaseName("ix_point_activity_claims_tenant_id_task_id");

                    b.HasIndex("TenantId", "UserId", "CreatedAt")
                        .HasDatabaseName("ix_point_activity_claims_tenant_id_user_id_created_at");

                    b.HasIndex("TenantId", "UserId", "TaskId", "SourceType", "SourceId")
                        .IsUnique()
                        .HasDatabaseName("ix_point_activity_claims_tenant_id_user_id_task_id_source_type~")
                        .HasFilter("source_type is not null and source_id is not null");

                    b.ToTable("point_activity_claims", null, t =>
                        {
                            t.HasCheckConstraint("ck_point_activity_claims_points", "points > 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.PointActivityTask", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("description");

                    b.Property<DateTimeOffset?>("EndsAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("ends_at");

                    b.Property<int>("MaxClaimsPerUser")
                        .HasColumnType("integer")
                        .HasColumnName("max_claims_per_user");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("Points")
                        .HasColumnType("integer")
                        .HasColumnName("points");

                    b.Property<JsonElement>("Rules")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("rules")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<DateTimeOffset?>("StartsAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("starts_at");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<string>("TaskKey")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("citext")
                        .HasColumnName("task_key");

                    b.Property<string>("TaskType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("task_type");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Title")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("title");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_point_activity_tasks");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_point_activity_tasks_tenant_id_id");

                    b.HasIndex("TenantId", "TaskKey")
                        .IsUnique()
                        .HasDatabaseName("ix_point_activity_tasks_tenant_id_task_key");

                    b.HasIndex("TenantId", "Status", "SortOrder")
                        .HasDatabaseName("ix_point_activity_tasks_tenant_id_status_sort_order");

                    b.ToTable("point_activity_tasks", null, t =>
                        {
                            t.HasCheckConstraint("ck_point_activity_tasks_max_claims", "max_claims_per_user > 0");

                            t.HasCheckConstraint("ck_point_activity_tasks_points", "points > 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.PointExchangeItem", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int?>("Days")
                        .HasColumnType("integer")
                        .HasColumnName("days");

                    b.Property<string>("Description")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("description");

                    b.Property<DateTimeOffset?>("EndsAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("ends_at");

                    b.Property<JsonElement>("FulfillmentPayload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("fulfillment_payload")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("ItemKey")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("citext")
                        .HasColumnName("item_key");

                    b.Property<string>("ItemType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("item_type");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<int>("PointsCost")
                        .HasColumnType("integer")
                        .HasColumnName("points_cost");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<DateTimeOffset?>("StartsAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("starts_at");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<int?>("Stock")
                        .HasColumnType("integer")
                        .HasColumnName("stock");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_point_exchange_items");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_point_exchange_items_tenant_id_id");

                    b.HasIndex("TenantId", "ItemKey")
                        .IsUnique()
                        .HasDatabaseName("ix_point_exchange_items_tenant_id_item_key");

                    b.HasIndex("TenantId", "RegionId", "Status", "SortOrder")
                        .HasDatabaseName("ix_point_exchange_items_tenant_id_region_id_status_sort_order");

                    b.ToTable("point_exchange_items", null, t =>
                        {
                            t.HasCheckConstraint("ck_point_exchange_items_days", "days is null or days >= 0");

                            t.HasCheckConstraint("ck_point_exchange_items_points_cost", "points_cost > 0");

                            t.HasCheckConstraint("ck_point_exchange_items_stock", "stock is null or stock >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.PointExchangeOrder", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset?>("CancelledAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("cancelled_at");

                    b.Property<DateTimeOffset?>("CompletedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("completed_at");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("FulfillmentSnapshot")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("fulfillment_snapshot")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid>("ItemId")
                        .HasColumnType("uuid")
                        .HasColumnName("item_id");

                    b.Property<string>("ItemName")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("item_name");

                    b.Property<string>("ItemType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("item_type");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("OrderNo")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("order_no");

                    b.Property<DateTimeOffset>("OrderedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("ordered_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int>("PointsCost")
                        .HasColumnType("integer")
                        .HasColumnName("points_cost");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_point_exchange_orders");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_point_exchange_orders_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_point_exchange_orders_user_id");

                    b.HasIndex("TenantId", "ItemId")
                        .HasDatabaseName("ix_point_exchange_orders_tenant_id_item_id");

                    b.HasIndex("TenantId", "OrderNo")
                        .IsUnique()
                        .HasDatabaseName("ix_point_exchange_orders_tenant_id_order_no");

                    b.HasIndex("TenantId", "UserId", "CreatedAt")
                        .HasDatabaseName("ix_point_exchange_orders_tenant_id_user_id_created_at");

                    b.ToTable("point_exchange_orders", null, t =>
                        {
                            t.HasCheckConstraint("ck_point_exchange_orders_points_cost", "points_cost > 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.Product", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Cover")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("cover");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("DetailImages")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("detail_images")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<bool>("IsActive")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("boolean")
                        .HasDefaultValue(true)
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("LegacyPriceText")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("legacy_price_text");

                    b.Property<string>("Link")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("link");

                    b.Property<string>("PreviewIframe")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("preview_iframe");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<JsonElement>("Tags")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("tags")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Title")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("title");

                    b.Property<string>("Type")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("type");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_products");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_products_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_products_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RegionId", "Type", "IsActive", "SortOrder")
                        .HasDatabaseName("ix_products_tenant_id_region_id_type_is_active_sort_order");

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

            modelBuilder.Entity("Tiku.Domain.Commerce.SvipPlan", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Badge")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("badge");

                    b.Property<bool>("CouponOnly")
                        .HasColumnType("boolean")
                        .HasColumnName("coupon_only");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int>("Days")
                        .HasColumnType("integer")
                        .HasColumnName("days");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<int?>("OriginalPriceCents")
                        .HasColumnType("integer")
                        .HasColumnName("original_price_cents");

                    b.Property<string>("PerDayLabel")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("per_day_label");

                    b.Property<int>("PriceCents")
                        .HasColumnType("integer")
                        .HasColumnName("price_cents");

                    b.Property<bool>("Recommended")
                        .HasColumnType("boolean")
                        .HasColumnName("recommended");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<bool>("VpEnabled")
                        .HasColumnType("boolean")
                        .HasColumnName("vp_enabled");

                    b.Property<string>("VpProductId")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("vp_product_id");

                    b.HasKey("Id")
                        .HasName("pk_svip_plans");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_svip_plans_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_svip_plans_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RegionId", "IsActive", "SortOrder")
                        .HasDatabaseName("ix_svip_plans_tenant_id_region_id_is_active_sort_order");

                    b.ToTable("svip_plans", null, t =>
                        {
                            t.HasCheckConstraint("ck_svip_plans_days", "days >= 0");

                            t.HasCheckConstraint("ck_svip_plans_price", "price_cents >= 0 and (original_price_cents is null or original_price_cents >= 0)");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Content.AiRecommendationReport", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<JsonElement>("ContextPayload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("context_payload")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("ErrorMessage")
                        .HasColumnType("text")
                        .HasColumnName("error_message");

                    b.Property<DateTimeOffset?>("GeneratedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("generated_at");

                    b.Property<JsonElement>("InputPayload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("input_payload")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Model")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("model");

                    b.Property<string>("PromptVersion")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("prompt_version");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("provider");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<JsonElement>("ResultPayload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("result_payload")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_ai_recommendation_reports");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_ai_recommendation_reports_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_ai_recommendation_reports_user_id");

                    b.HasIndex("TenantId", "RegionId", "CreatedAt")
                        .HasDatabaseName("ix_ai_recommendation_reports_tenant_id_region_id_created_at");

                    b.HasIndex("TenantId", "UserId", "CreatedAt")
                        .HasDatabaseName("ix_ai_recommendation_reports_tenant_id_user_id_created_at");

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

            modelBuilder.Entity("Tiku.Domain.Content.AppAsset", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("AssetKey")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("asset_key");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("description");

                    b.Property<string>("FileName")
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("file_name");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_app_assets");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_app_assets_tenant_id_id");

                    b.HasIndex("TenantId", "AssetKey")
                        .IsUnique()
                        .HasDatabaseName("ix_app_assets_tenant_id_asset_key");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_app_assets_tenant_id_legacy_id");

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

            modelBuilder.Entity("Tiku.Domain.Content.ContentAsset", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<JsonElement>("AccessRules")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("access_rules")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("AssetKey")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("asset_key");

                    b.Property<string>("AssetType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("asset_type");

                    b.Property<string>("Bucket")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("bucket");

                    b.Property<string>("Category")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("category");

                    b.Property<Guid?>("CategoryId")
                        .HasColumnType("uuid")
                        .HasColumnName("category_id");

                    b.Property<string>("CdnUrl")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("cdn_url");

                    b.Property<string>("ChecksumSha256")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("checksum_sha256");

                    b.Property<Guid?>("ContentNodeId")
                        .HasColumnType("uuid")
                        .HasColumnName("content_node_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<int>("DownloadCount")
                        .HasColumnType("integer")
                        .HasColumnName("download_count");

                    b.Property<string>("FileName")
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("file_name");

                    b.Property<long?>("FileSizeBytes")
                        .HasColumnType("bigint")
                        .HasColumnName("file_size_bytes");

                    b.Property<bool>("IsPublic")
                        .HasColumnType("boolean")
                        .HasColumnName("is_public");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("MimeType")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("mime_type");

                    b.Property<string>("ObjectKey")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("object_key");

                    b.Property<string>("PreviewObjectKey")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("preview_object_key");

                    b.Property<string>("PreviewStatus")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("preview_status");

                    b.Property<string>("PreviewUrl")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("preview_url");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<JsonElement>("SecurityFlags")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("security_flags")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("SecurityScanProvider")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("security_scan_provider");

                    b.Property<string>("SecurityScanStatus")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasDefaultValue("not_required")
                        .HasColumnName("security_scan_status");

                    b.Property<JsonElement>("SecurityScanSummary")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("security_scan_summary")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset?>("SecurityScannedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("security_scanned_at");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("Source")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("source");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<string>("StorageProvider")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("storage_provider");

                    b.Property<Guid?>("SubjectId")
                        .HasColumnType("uuid")
                        .HasColumnName("subject_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Title")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("title");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UpdatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("updated_by");

                    b.Property<string>("UploadStatus")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("upload_status");

                    b.Property<JsonElement>("VerificationDetails")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("verification_details")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset?>("VerifiedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("verified_at");

                    b.Property<Guid?>("VerifiedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("verified_by");

                    b.Property<string>("VerifiedChecksumSha256")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("verified_checksum_sha256");

                    b.Property<long?>("VerifiedSizeBytes")
                        .HasColumnType("bigint")
                        .HasColumnName("verified_size_bytes");

                    b.Property<string>("Visibility")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("visibility");

                    b.HasKey("Id")
                        .HasName("pk_content_assets");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_content_assets_tenant_id_id");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_content_assets_created_by");

                    b.HasIndex("UpdatedBy")
                        .HasDatabaseName("ix_content_assets_updated_by");

                    b.HasIndex("VerifiedBy")
                        .HasDatabaseName("ix_content_assets_verified_by");

                    b.HasIndex("TenantId", "CategoryId")
                        .HasDatabaseName("ix_content_assets_tenant_id_category_id");

                    b.HasIndex("TenantId", "ChecksumSha256")
                        .HasDatabaseName("ix_content_assets_tenant_id_checksum_sha256")
                        .HasFilter("checksum_sha256 is not null");

                    b.HasIndex("TenantId", "ContentNodeId")
                        .HasDatabaseName("ix_content_assets_tenant_id_content_node_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_content_assets_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "PreviewStatus")
                        .HasDatabaseName("ix_content_assets_tenant_id_preview_status")
                        .HasFilter("preview_status <> 'none'");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_content_assets_tenant_id_region_id");

                    b.HasIndex("TenantId", "SubjectId")
                        .HasDatabaseName("ix_content_assets_tenant_id_subject_id");

                    b.HasIndex("TenantId", "StorageProvider", "Bucket", "ObjectKey")
                        .HasDatabaseName("ix_content_assets_tenant_id_storage_provider_bucket_object_key");

                    b.HasIndex("TenantId", "UploadStatus", "Status", "UpdatedAt")
                        .HasDatabaseName("ix_content_assets_tenant_id_upload_status_status_updated_at");

                    b.HasIndex("TenantId", "SecurityScanStatus", "UploadStatus", "Status", "UpdatedAt")
                        .HasDatabaseName("ix_content_assets_tenant_id_security_scan_status_upload_status~");

                    b.HasIndex("TenantId", "Status", "Visibility", "AssetType", "RegionId", "SubjectId", "CategoryId", "SortOrder")
                        .HasDatabaseName("ix_content_assets_tenant_id_status_visibility_asset_type_regio~");

                    b.ToTable("content_assets", null, t =>
                        {
                            t.HasCheckConstraint("ck_content_assets_download_count", "download_count >= 0");

                            t.HasCheckConstraint("ck_content_assets_file_size", "file_size_bytes is null or file_size_bytes >= 0");

                            t.HasCheckConstraint("ck_content_assets_verified_checksum", "verified_checksum_sha256 is null or verified_checksum_sha256 ~ '^[a-f0-9]{64}$'");

                            t.HasCheckConstraint("ck_content_assets_verified_size", "verified_size_bytes is null or verified_size_bytes >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Content.ContentAssetAccessEvent", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("AccessType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("access_type");

                    b.Property<string>("ActorRole")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("actor_role");

                    b.Property<Guid?>("AssetId")
                        .HasColumnType("uuid")
                        .HasColumnName("asset_id");

                    b.Property<string>("AssetType")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("asset_type");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("DenyCode")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("deny_code");

                    b.Property<string>("Disposition")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("disposition");

                    b.Property<int?>("ExpiresInSeconds")
                        .HasColumnType("integer")
                        .HasColumnName("expires_in_seconds");

                    b.Property<string>("IpAddress")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("ip_address");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Result")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("result");

                    b.Property<string>("SignatureMode")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("signature_mode");

                    b.Property<string>("StorageProvider")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("storage_provider");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("UserAgent")
                        .HasMaxLength(1024)
                        .HasColumnType("character varying(1024)")
                        .HasColumnName("user_agent");

                    b.Property<Guid?>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.Property<string>("Visibility")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("visibility");

                    b.HasKey("Id")
                        .HasName("pk_content_asset_access_events");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_content_asset_access_events_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_content_asset_access_events_user_id");

                    b.HasIndex("TenantId", "AssetId", "CreatedAt")
                        .HasDatabaseName("ix_content_asset_access_events_tenant_id_asset_id_created_at");

                    b.HasIndex("TenantId", "UserId", "CreatedAt")
                        .HasDatabaseName("ix_content_asset_access_events_tenant_id_user_id_created_at")
                        .HasFilter("user_id is not null");

                    b.HasIndex("TenantId", "AccessType", "Result", "CreatedAt")
                        .HasDatabaseName("ix_content_asset_access_events_tenant_id_access_type_result_cr~");

                    b.ToTable("content_asset_access_events", null, t =>
                        {
                            t.HasCheckConstraint("ck_content_asset_access_events_expiry", "expires_in_seconds is null or expires_in_seconds > 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Content.ContentAssetSecurityScanEvent", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid?>("AssetId")
                        .HasColumnType("uuid")
                        .HasColumnName("asset_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("Details")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("details")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.PrimitiveCollection<string[]>("IssueCodes")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasColumnType("text[]")
                        .HasColumnName("issue_codes")
                        .HasDefaultValueSql("'{}'::text[]");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("provider");

                    b.Property<string>("RiskLevel")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("risk_level");

                    b.Property<string>("ScanStatus")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("scan_status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.HasKey("Id")
                        .HasName("pk_content_asset_security_scan_events");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_content_asset_security_scan_events_tenant_id_id");

                    b.HasIndex("TenantId", "AssetId", "CreatedAt")
                        .HasDatabaseName("ix_content_asset_security_scan_events_tenant_id_asset_id_creat~");

                    b.HasIndex("TenantId", "ScanStatus", "RiskLevel", "CreatedAt")
                        .HasDatabaseName("ix_content_asset_security_scan_events_tenant_id_scan_status_ri~");

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

            modelBuilder.Entity("Tiku.Domain.Content.ContentEntry", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<JsonElement>("AccessRules")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("access_rules")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<string>("Description")
                        .HasMaxLength(2000)
                        .HasColumnType("character varying(2000)")
                        .HasColumnName("description");

                    b.Property<string>("EntryKey")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("entry_key");

                    b.Property<string>("EntryType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("entry_type");

                    b.Property<string>("Icon")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("icon");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<JsonElement>("LayoutConfig")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("layout_config")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("name");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<string>("Route")
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("route");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UpdatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("updated_by");

                    b.Property<string>("Visibility")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("visibility");

                    b.HasKey("Id")
                        .HasName("pk_content_entries");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_content_entries_tenant_id_id");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_content_entries_created_by");

                    b.HasIndex("UpdatedBy")
                        .HasDatabaseName("ix_content_entries_updated_by");

                    b.HasIndex("TenantId", "EntryKey")
                        .IsUnique()
                        .HasDatabaseName("ix_content_entries_tenant_id_entry_key");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_content_entries_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RegionId", "EntryType", "IsActive", "SortOrder")
                        .HasDatabaseName("ix_content_entries_tenant_id_region_id_entry_type_is_active_so~");

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

            modelBuilder.Entity("Tiku.Domain.Content.ContentImportIssue", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Code")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("code");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("Details")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("details")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("FieldPath")
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("field_path");

                    b.Property<Guid?>("ItemId")
                        .HasColumnType("uuid")
                        .HasColumnName("item_id");

                    b.Property<Guid>("JobId")
                        .HasColumnType("uuid")
                        .HasColumnName("job_id");

                    b.Property<string>("Message")
                        .IsRequired()
                        .HasMaxLength(2000)
                        .HasColumnType("character varying(2000)")
                        .HasColumnName("message");

                    b.Property<int?>("RowNo")
                        .HasColumnType("integer")
                        .HasColumnName("row_no");

                    b.Property<string>("Severity")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("severity");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_content_import_issues");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_content_import_issues_tenant_id_id");

                    b.HasIndex("TenantId", "ItemId")
                        .HasDatabaseName("ix_content_import_issues_tenant_id_item_id");

                    b.HasIndex("TenantId", "JobId", "Severity", "RowNo")
                        .HasDatabaseName("ix_content_import_issues_tenant_id_job_id_severity_row_no");

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

            modelBuilder.Entity("Tiku.Domain.Content.ContentImportItem", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("ContentHash")
                        .HasMaxLength(128)
                        .HasColumnType("character varying(128)")
                        .HasColumnName("content_hash");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("ExternalId")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("external_id");

                    b.Property<int>("IssuesCount")
                        .HasColumnType("integer")
                        .HasColumnName("issues_count");

                    b.Property<Guid>("JobId")
                        .HasColumnType("uuid")
                        .HasColumnName("job_id");

                    b.Property<JsonElement>("NormalizedPayload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("normalized_payload")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("RowNo")
                        .HasColumnType("integer")
                        .HasColumnName("row_no");

                    b.Property<JsonElement>("SourcePayload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("source_payload")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid?>("TargetId")
                        .HasColumnType("uuid")
                        .HasColumnName("target_id");

                    b.Property<string>("TargetType")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("target_type");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_content_import_items");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_content_import_items_tenant_id_id");

                    b.HasIndex("TenantId", "JobId", "RowNo")
                        .IsUnique()
                        .HasDatabaseName("ix_content_import_items_tenant_id_job_id_row_no");

                    b.HasIndex("TenantId", "JobId", "Status", "RowNo")
                        .HasDatabaseName("ix_content_import_items_tenant_id_job_id_status_row_no");

                    b.ToTable("content_import_items", null, t =>
                        {
                            t.HasCheckConstraint("ck_content_import_items_issues_count", "issues_count >= 0");

                            t.HasCheckConstraint("ck_content_import_items_row_no", "row_no >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Content.ContentImportJob", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<bool>("DryRun")
                        .HasColumnType("boolean")
                        .HasColumnName("dry_run");

                    b.Property<int>("ErrorCount")
                        .HasColumnType("integer")
                        .HasColumnName("error_count");

                    b.Property<string>("ErrorMessage")
                        .HasColumnType("text")
                        .HasColumnName("error_message");

                    b.Property<DateTimeOffset?>("FinishedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("finished_at");

                    b.Property<string>("ImportType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("import_type");

                    b.Property<int>("InsertedCount")
                        .HasColumnType("integer")
                        .HasColumnName("inserted_count");

                    b.Property<JsonElement>("NormalizedPayload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("normalized_payload")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<JsonElement>("RawPayload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("raw_payload")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<int>("SkippedCount")
                        .HasColumnType("integer")
                        .HasColumnName("skipped_count");

                    b.Property<string>("SourceFormat")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("source_format");

                    b.Property<string>("SourceHash")
                        .HasMaxLength(128)
                        .HasColumnType("character varying(128)")
                        .HasColumnName("source_hash");

                    b.Property<string>("SourceName")
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("source_name");

                    b.Property<DateTimeOffset?>("StartedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("started_at");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<JsonElement>("Summary")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("summary")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid?>("TargetCategoryId")
                        .HasColumnType("uuid")
                        .HasColumnName("target_category_id");

                    b.Property<Guid?>("TargetContentNodeId")
                        .HasColumnType("uuid")
                        .HasColumnName("target_content_node_id");

                    b.Property<Guid?>("TargetQuestionBankId")
                        .HasColumnType("uuid")
                        .HasColumnName("target_question_bank_id");

                    b.Property<Guid?>("TargetRegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("target_region_id");

                    b.Property<Guid?>("TargetSubjectId")
                        .HasColumnType("uuid")
                        .HasColumnName("target_subject_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<int>("TotalCount")
                        .HasColumnType("integer")
                        .HasColumnName("total_count");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int>("UpdatedCount")
                        .HasColumnType("integer")
                        .HasColumnName("updated_count");

                    b.Property<int>("ValidCount")
                        .HasColumnType("integer")
                        .HasColumnName("valid_count");

                    b.Property<int>("WarningCount")
                        .HasColumnType("integer")
                        .HasColumnName("warning_count");

                    b.HasKey("Id")
                        .HasName("pk_content_import_jobs");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_content_import_jobs_tenant_id_id");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_content_import_jobs_created_by");

                    b.HasIndex("TenantId", "TargetCategoryId")
                        .HasDatabaseName("ix_content_import_jobs_tenant_id_target_category_id");

                    b.HasIndex("TenantId", "TargetContentNodeId")
                        .HasDatabaseName("ix_content_import_jobs_tenant_id_target_content_node_id");

                    b.HasIndex("TenantId", "TargetQuestionBankId")
                        .HasDatabaseName("ix_content_import_jobs_tenant_id_target_question_bank_id");

                    b.HasIndex("TenantId", "TargetRegionId")
                        .HasDatabaseName("ix_content_import_jobs_tenant_id_target_region_id");

                    b.HasIndex("TenantId", "TargetSubjectId")
                        .HasDatabaseName("ix_content_import_jobs_tenant_id_target_subject_id");

                    b.HasIndex("TenantId", "ImportType", "Status", "CreatedAt")
                        .HasDatabaseName("ix_content_import_jobs_tenant_id_import_type_status_created_at");

                    b.ToTable("content_import_jobs", null, t =>
                        {
                            t.HasCheckConstraint("ck_content_import_jobs_counts", "total_count >= 0 and valid_count >= 0 and error_count >= 0 and warning_count >= 0 and inserted_count >= 0 and updated_count >= 0 and skipped_count >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Content.ContentNode", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<JsonElement>("AccessRules")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("access_rules")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<int>("Depth")
                        .HasColumnType("integer")
                        .HasColumnName("depth");

                    b.Property<Guid>("EntryId")
                        .HasColumnType("uuid")
                        .HasColumnName("entry_id");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<bool>("IsLeaf")
                        .HasColumnType("boolean")
                        .HasColumnName("is_leaf");

                    b.Property<bool>("IsSelectable")
                        .HasColumnType("boolean")
                        .HasColumnName("is_selectable");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("MarkerConfig")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("marker_config")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("MarkerType")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("marker_type");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("name");

                    b.Property<string>("NodeKey")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("node_key");

                    b.Property<string>("NodeType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("node_type");

                    b.Property<Guid?>("ParentId")
                        .HasColumnType("uuid")
                        .HasColumnName("parent_id");

                    b.Property<string>("Path")
                        .HasColumnType("ltree")
                        .HasColumnName("path");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UpdatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("updated_by");

                    b.HasKey("Id")
                        .HasName("pk_content_nodes");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_content_nodes_tenant_id_id");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_content_nodes_created_by");

                    b.HasIndex("Path")
                        .HasDatabaseName("ix_content_nodes_path");

                    NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("Path"), "gist");

                    b.HasIndex("UpdatedBy")
                        .HasDatabaseName("ix_content_nodes_updated_by");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_content_nodes_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "MarkerType")
                        .HasDatabaseName("ix_content_nodes_tenant_id_marker_type")
                        .HasFilter("marker_type is not null");

                    b.HasIndex("TenantId", "ParentId")
                        .HasDatabaseName("ix_content_nodes_tenant_id_parent_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_content_nodes_tenant_id_region_id");

                    b.HasIndex("TenantId", "EntryId", "NodeKey")
                        .IsUnique()
                        .HasDatabaseName("ix_content_nodes_tenant_id_entry_id_node_key");

                    b.HasIndex("TenantId", "EntryId", "ParentId", "SortOrder")
                        .HasDatabaseName("ix_content_nodes_tenant_id_entry_id_parent_id_sort_order");

                    b.ToTable("content_nodes", null, t =>
                        {
                            t.HasCheckConstraint("ck_content_nodes_depth", "depth >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Content.HandbookChapter", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid?>("ContentNodeId")
                        .HasColumnType("uuid")
                        .HasColumnName("content_node_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<Guid?>("EntryId")
                        .HasColumnType("uuid")
                        .HasColumnName("entry_id");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("name");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("SourceHash")
                        .HasMaxLength(128)
                        .HasColumnType("character varying(128)")
                        .HasColumnName("source_hash");

                    b.Property<Guid?>("SubjectId")
                        .HasColumnType("uuid")
                        .HasColumnName("subject_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_handbook_chapters");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_handbook_chapters_tenant_id_id");

                    b.HasIndex("TenantId", "ContentNodeId")
                        .HasDatabaseName("ix_handbook_chapters_tenant_id_content_node_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_handbook_chapters_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "SubjectId")
                        .HasDatabaseName("ix_handbook_chapters_tenant_id_subject_id");

                    b.HasIndex("TenantId", "EntryId", "ContentNodeId", "SubjectId", "IsActive", "SortOrder")
                        .HasDatabaseName("ix_handbook_chapters_tenant_id_entry_id_content_node_id_subjec~");

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

            modelBuilder.Entity("Tiku.Domain.Content.HandbookEntry", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid?>("ChapterId")
                        .HasColumnType("uuid")
                        .HasColumnName("chapter_id");

                    b.Property<string>("Content")
                        .HasColumnType("text")
                        .HasColumnName("content");

                    b.Property<Guid?>("ContentNodeId")
                        .HasColumnType("uuid")
                        .HasColumnName("content_node_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("EntryId")
                        .HasColumnType("uuid")
                        .HasColumnName("entry_id");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("SourceHash")
                        .HasMaxLength(128)
                        .HasColumnType("character varying(128)")
                        .HasColumnName("source_hash");

                    b.Property<string>("Summary")
                        .HasColumnType("text")
                        .HasColumnName("summary");

                    b.Property<JsonElement>("Tags")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("tags")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Title")
                        .IsRequired()
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("title");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_handbook_entries");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_handbook_entries_tenant_id_id");

                    b.HasIndex("TenantId", "ChapterId")
                        .HasDatabaseName("ix_handbook_entries_tenant_id_chapter_id");

                    b.HasIndex("TenantId", "ContentNodeId")
                        .HasDatabaseName("ix_handbook_entries_tenant_id_content_node_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_handbook_entries_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "EntryId", "ContentNodeId", "ChapterId", "IsActive", "SortOrder")
                        .HasDatabaseName("ix_handbook_entries_tenant_id_entry_id_content_node_id_chapter~");

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

            modelBuilder.Entity("Tiku.Domain.Content.HandbookSubject", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Color")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("color");

                    b.Property<Guid?>("ContentNodeId")
                        .HasColumnType("uuid")
                        .HasColumnName("content_node_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<Guid?>("EntryId")
                        .HasColumnType("uuid")
                        .HasColumnName("entry_id");

                    b.Property<string>("Icon")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("icon");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<Guid?>("MajorId")
                        .HasColumnType("uuid")
                        .HasColumnName("major_id");

                    b.Property<JsonElement>("MajorLegacyIds")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("major_legacy_ids")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("name");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<Guid?>("SchoolId")
                        .HasColumnType("uuid")
                        .HasColumnName("school_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("SourceHash")
                        .HasMaxLength(128)
                        .HasColumnType("character varying(128)")
                        .HasColumnName("source_hash");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Type")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("type");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_handbook_subjects");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_handbook_subjects_tenant_id_id");

                    b.HasIndex("TenantId", "ContentNodeId")
                        .HasDatabaseName("ix_handbook_subjects_tenant_id_content_node_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_handbook_subjects_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "MajorId")
                        .HasDatabaseName("ix_handbook_subjects_tenant_id_major_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_handbook_subjects_tenant_id_region_id");

                    b.HasIndex("TenantId", "SchoolId")
                        .HasDatabaseName("ix_handbook_subjects_tenant_id_school_id");

                    b.HasIndex("TenantId", "EntryId", "ContentNodeId", "RegionId", "IsActive", "SortOrder")
                        .HasDatabaseName("ix_handbook_subjects_tenant_id_entry_id_content_node_id_region~");

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

            modelBuilder.Entity("Tiku.Domain.Content.ImageAsset", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Category")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("category");

                    b.Property<string>("CdnUrl")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("cdn_url");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("FileName")
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("file_name");

                    b.Property<bool>("IsPublic")
                        .HasColumnType("boolean")
                        .HasColumnName("is_public");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Title")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("title");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_images");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_images_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_images_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "Category", "IsPublic")
                        .HasDatabaseName("ix_images_tenant_id_category_is_public");

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

            modelBuilder.Entity("Tiku.Domain.Content.PracticeBlueprint", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<JsonElement>("AccessRules")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("access_rules")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("AssemblyType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("assembly_type");

                    b.Property<Guid?>("CollectionId")
                        .HasColumnType("uuid")
                        .HasColumnName("collection_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<int?>("DurationMinutes")
                        .HasColumnType("integer")
                        .HasColumnName("duration_minutes");

                    b.Property<Guid?>("EntryId")
                        .HasColumnType("uuid")
                        .HasColumnName("entry_id");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("Mode")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("mode");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("name");

                    b.Property<Guid?>("NodeId")
                        .HasColumnType("uuid")
                        .HasColumnName("node_id");

                    b.Property<decimal?>("PassScore")
                        .HasPrecision(8, 2)
                        .HasColumnType("numeric(8,2)")
                        .HasColumnName("pass_score");

                    b.Property<int?>("QuestionLimit")
                        .HasColumnType("integer")
                        .HasColumnName("question_limit");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<JsonElement>("Rules")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("rules")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<JsonElement>("Sections")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("sections")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<decimal?>("TotalScore")
                        .HasPrecision(8, 2)
                        .HasColumnType("numeric(8,2)")
                        .HasColumnName("total_score");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UpdatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("updated_by");

                    b.HasKey("Id")
                        .HasName("pk_practice_blueprints");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_practice_blueprints_tenant_id_id");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_practice_blueprints_created_by");

                    b.HasIndex("UpdatedBy")
                        .HasDatabaseName("ix_practice_blueprints_updated_by");

                    b.HasIndex("TenantId", "CollectionId")
                        .HasDatabaseName("ix_practice_blueprints_tenant_id_collection_id");

                    b.HasIndex("TenantId", "EntryId")
                        .HasDatabaseName("ix_practice_blueprints_tenant_id_entry_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_practice_blueprints_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_practice_blueprints_tenant_id_region_id");

                    b.HasIndex("TenantId", "NodeId", "CollectionId", "Mode", "Status", "SortOrder")
                        .HasDatabaseName("ix_practice_blueprints_tenant_id_node_id_collection_id_mode_st~");

                    b.ToTable("practice_blueprints", null, t =>
                        {
                            t.HasCheckConstraint("ck_practice_blueprints_duration", "duration_minutes is null or duration_minutes > 0");

                            t.HasCheckConstraint("ck_practice_blueprints_question_limit", "question_limit is null or question_limit > 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Content.QuestionCollection", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<JsonElement>("AccessRules")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("access_rules")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid?>("CategoryId")
                        .HasColumnType("uuid")
                        .HasColumnName("category_id");

                    b.Property<string>("CollectionType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("collection_type");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<int?>("DurationMinutes")
                        .HasColumnType("integer")
                        .HasColumnName("duration_minutes");

                    b.Property<Guid?>("EntryId")
                        .HasColumnType("uuid")
                        .HasColumnName("entry_id");

                    b.Property<JsonElement>("Filters")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("filters")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("name");

                    b.Property<Guid?>("NodeId")
                        .HasColumnType("uuid")
                        .HasColumnName("node_id");

                    b.Property<Guid?>("QuestionBankId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_bank_id");

                    b.Property<int>("QuestionCount")
                        .HasColumnType("integer")
                        .HasColumnName("question_count");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("SourceType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("source_type");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid?>("SubjectId")
                        .HasColumnType("uuid")
                        .HasColumnName("subject_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<decimal?>("TotalScore")
                        .HasPrecision(8, 2)
                        .HasColumnType("numeric(8,2)")
                        .HasColumnName("total_score");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UpdatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("updated_by");

                    b.HasKey("Id")
                        .HasName("pk_question_collections");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_question_collections_tenant_id_id");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_question_collections_created_by");

                    b.HasIndex("UpdatedBy")
                        .HasDatabaseName("ix_question_collections_updated_by");

                    b.HasIndex("TenantId", "CategoryId")
                        .HasDatabaseName("ix_question_collections_tenant_id_category_id");

                    b.HasIndex("TenantId", "EntryId")
                        .HasDatabaseName("ix_question_collections_tenant_id_entry_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_question_collections_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "QuestionBankId")
                        .HasDatabaseName("ix_question_collections_tenant_id_question_bank_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_question_collections_tenant_id_region_id");

                    b.HasIndex("TenantId", "SubjectId")
                        .HasDatabaseName("ix_question_collections_tenant_id_subject_id");

                    b.HasIndex("TenantId", "NodeId", "Status", "SortOrder")
                        .HasDatabaseName("ix_question_collections_tenant_id_node_id_status_sort_order");

                    b.ToTable("question_collections", null, t =>
                        {
                            t.HasCheckConstraint("ck_question_collections_duration", "duration_minutes is null or duration_minutes > 0");

                            t.HasCheckConstraint("ck_question_collections_question_count", "question_count >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Content.QuestionCollectionItem", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid>("CollectionId")
                        .HasColumnType("uuid")
                        .HasColumnName("collection_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid>("QuestionId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_id");

                    b.Property<Guid>("QuestionOwnerTenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_owner_tenant_id");

                    b.Property<Guid>("QuestionReferenceId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_reference_id");

                    b.Property<bool>("Required")
                        .HasColumnType("boolean")
                        .HasColumnName("required");

                    b.Property<decimal?>("Score")
                        .HasPrecision(8, 2)
                        .HasColumnType("numeric(8,2)")
                        .HasColumnName("score");

                    b.Property<string>("SectionKey")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("section_key");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_question_collection_items");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_question_collection_items_tenant_id_id");

                    b.HasIndex("QuestionOwnerTenantId", "QuestionId")
                        .HasDatabaseName("ix_question_collection_items_question_owner_tenant_id_question~");

                    b.HasIndex("TenantId", "QuestionReferenceId")
                        .HasDatabaseName("ix_question_collection_items_tenant_id_question_reference_id");

                    b.HasIndex("TenantId", "CollectionId", "QuestionReferenceId")
                        .IsUnique()
                        .HasDatabaseName("ix_question_collection_items_tenant_id_collection_id_question_~");

                    b.HasIndex("TenantId", "CollectionId", "SectionKey", "SortOrder")
                        .HasDatabaseName("ix_question_collection_items_tenant_id_collection_id_section_k~");

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

            modelBuilder.Entity("Tiku.Domain.Content.QuestionTypeGroup", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("DisplayName")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("display_name");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid?>("SubjectId")
                        .HasColumnType("uuid")
                        .HasColumnName("subject_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<JsonElement>("Types")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("types")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_question_type_groups");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_question_type_groups_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_question_type_groups_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "SubjectId", "IsActive", "SortOrder")
                        .HasDatabaseName("ix_question_type_groups_tenant_id_subject_id_is_active_sort_or~");

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

            modelBuilder.Entity("Tiku.Domain.Content.QuestionVideo", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("LegacyQuestionId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_question_id");

                    b.Property<string>("LegacyVideoId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_video_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid?>("QuestionId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("VideoId")
                        .HasColumnType("uuid")
                        .HasColumnName("video_id");

                    b.Property<string>("VideoType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("video_type");

                    b.HasKey("Id")
                        .HasName("pk_question_videos");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_question_videos_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_question_videos_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "VideoId")
                        .HasDatabaseName("ix_question_videos_tenant_id_video_id");

                    b.HasIndex("TenantId", "QuestionId", "VideoId", "VideoType")
                        .IsUnique()
                        .HasDatabaseName("ix_question_videos_tenant_id_question_id_video_id_video_type");

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

            modelBuilder.Entity("Tiku.Domain.Content.SubjectShare", b =>
                {
                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<Guid>("SourceSubjectId")
                        .HasColumnType("uuid")
                        .HasColumnName("source_subject_id");

                    b.Property<Guid>("TargetSubjectId")
                        .HasColumnType("uuid")
                        .HasColumnName("target_subject_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("Id")
                        .HasColumnType("uuid")
                        .HasColumnName("id");

                    b.Property<string>("LegacyId")
                        .HasColumnType("text")
                        .HasColumnName("legacy_id");

                    b.Property<string>("LegacySourceSubjectId")
                        .HasColumnType("text")
                        .HasColumnName("legacy_source_subject_id");

                    b.Property<string>("LegacyTargetSubjectId")
                        .HasColumnType("text")
                        .HasColumnName("legacy_target_subject_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at");

                    b.HasKey("TenantId", "SourceSubjectId", "TargetSubjectId")
                        .HasName("pk_subject_shares");

                    b.HasIndex("TenantId", "TargetSubjectId")
                        .HasDatabaseName("ix_subject_shares_tenant_id_target_subject_id");

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

            modelBuilder.Entity("Tiku.Domain.Content.TenantQuestionBankPreference", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Alias")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("alias");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<bool>("IsVisible")
                        .HasColumnType("boolean")
                        .HasColumnName("is_visible");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("NavigationLocation")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("navigation_location");

                    b.Property<Guid>("QuestionBankId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_bank_id");

                    b.Property<Guid>("QuestionBankOwnerTenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_bank_owner_tenant_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UpdatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("updated_by");

                    b.HasKey("Id")
                        .HasName("pk_tenant_question_bank_preferences");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_question_bank_preferences_tenant_id_id");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_tenant_question_bank_preferences_created_by");

                    b.HasIndex("UpdatedBy")
                        .HasDatabaseName("ix_tenant_question_bank_preferences_updated_by");

                    b.HasIndex("QuestionBankOwnerTenantId", "QuestionBankId")
                        .HasDatabaseName("ix_tenant_question_bank_preferences_question_bank_owner_tenant~");

                    b.HasIndex("TenantId", "QuestionBankOwnerTenantId", "QuestionBankId")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_question_bank_preferences_tenant_id_question_bank_ow~");

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

            modelBuilder.Entity("Tiku.Domain.Content.TenantQuestionReference", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<Guid>("QuestionId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_id");

                    b.Property<Guid>("QuestionOwnerTenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_owner_tenant_id");

                    b.Property<string>("Source")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("source");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_tenant_question_references");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_question_references_tenant_id_id");

                    b.HasAlternateKey("TenantId", "QuestionOwnerTenantId", "QuestionId")
                        .HasName("ak_tenant_question_references_tenant_id_question_owner_tenant_~");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_tenant_question_references_created_by");

                    b.HasIndex("QuestionOwnerTenantId", "QuestionId")
                        .HasDatabaseName("ix_tenant_question_references_question_owner_tenant_id_questio~");

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

            modelBuilder.Entity("Tiku.Domain.Content.UserWordFavorite", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset?>("FavoritedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("favorited_at");

                    b.Property<string>("LegacyId")
                        .HasColumnType("text")
                        .HasColumnName("legacy_id");

                    b.Property<string>("LegacyUserId")
                        .HasColumnType("text")
                        .HasColumnName("legacy_user_id");

                    b.Property<string>("LegacyWordId")
                        .HasColumnType("text")
                        .HasColumnName("legacy_word_id");

                    b.Property<string>("Note")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("note");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.Property<Guid>("WordId")
                        .HasColumnType("uuid")
                        .HasColumnName("word_id");

                    b.HasKey("Id")
                        .HasName("pk_user_word_favorites");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_user_word_favorites_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_user_word_favorites_user_id");

                    b.HasIndex("TenantId", "WordId")
                        .HasDatabaseName("ix_user_word_favorites_tenant_id_word_id");

                    b.HasIndex("TenantId", "UserId", "WordId")
                        .IsUnique()
                        .HasDatabaseName("ix_user_word_favorites_tenant_id_user_id_word_id");

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

            modelBuilder.Entity("Tiku.Domain.Content.UserWordProgress", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("CorrectCount")
                        .HasColumnType("integer")
                        .HasColumnName("correct_count");

                    b.Property<int>("CorrectStreak")
                        .HasColumnType("integer")
                        .HasColumnName("correct_streak");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("DueLevel")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("due_level");

                    b.Property<decimal>("EaseFactor")
                        .ValueGeneratedOnAdd()
                        .HasPrecision(4, 2)
                        .HasColumnType("numeric(4,2)")
                        .HasDefaultValue(2.50m)
                        .HasColumnName("ease_factor");

                    b.Property<string>("LastResult")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("last_result");

                    b.Property<DateTimeOffset?>("LastReviewAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("last_review_at");

                    b.Property<string>("LegacyId")
                        .HasColumnType("text")
                        .HasColumnName("legacy_id");

                    b.Property<string>("LegacyUserId")
                        .HasColumnType("text")
                        .HasColumnName("legacy_user_id");

                    b.Property<string>("LegacyWordId")
                        .HasColumnType("text")
                        .HasColumnName("legacy_word_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset?>("NextReviewAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("next_review_at");

                    b.Property<int>("ReviewCount")
                        .HasColumnType("integer")
                        .HasColumnName("review_count");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.Property<Guid>("WordId")
                        .HasColumnType("uuid")
                        .HasColumnName("word_id");

                    b.Property<int>("WrongCount")
                        .HasColumnType("integer")
                        .HasColumnName("wrong_count");

                    b.HasKey("Id")
                        .HasName("pk_user_word_progress");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_user_word_progress_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_user_word_progress_user_id");

                    b.HasIndex("TenantId", "WordId")
                        .HasDatabaseName("ix_user_word_progress_tenant_id_word_id");

                    b.HasIndex("TenantId", "UserId", "WordId")
                        .IsUnique()
                        .HasDatabaseName("ix_user_word_progress_tenant_id_user_id_word_id");

                    b.HasIndex("TenantId", "UserId", "NextReviewAt", "Status", "DueLevel")
                        .HasDatabaseName("ix_user_word_progress_tenant_id_user_id_next_review_at_status_~");

                    b.ToTable("user_word_progress", null, t =>
                        {
                            t.HasCheckConstraint("ck_user_word_progress_correct_streak", "correct_streak >= 0");

                            t.HasCheckConstraint("ck_user_word_progress_ease_factor", "ease_factor >= 1.30 and ease_factor <= 3.00");

                            t.HasCheckConstraint("ck_user_word_progress_review_count", "review_count >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Content.VideoExplanation", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<int?>("Difficulty")
                        .HasColumnType("integer")
                        .HasColumnName("difficulty");

                    b.Property<int?>("DurationSeconds")
                        .HasColumnType("integer")
                        .HasColumnName("duration_seconds");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<bool>("IsGeneral")
                        .HasColumnType("boolean")
                        .HasColumnName("is_general");

                    b.Property<JsonElement>("KnowledgeTags")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("knowledge_tags")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("LegacySubjectId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_subject_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("SourceHash")
                        .HasMaxLength(128)
                        .HasColumnType("character varying(128)")
                        .HasColumnName("source_hash");

                    b.Property<Guid?>("SubjectId")
                        .HasColumnType("uuid")
                        .HasColumnName("subject_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("ThumbnailUrl")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("thumbnail_url");

                    b.Property<string>("Title")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("title");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("VideoUrl")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("video_url");

                    b.HasKey("Id")
                        .HasName("pk_video_explanations");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_video_explanations_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_video_explanations_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "SourceHash")
                        .HasDatabaseName("ix_video_explanations_tenant_id_source_hash")
                        .HasFilter("source_hash is not null");

                    b.HasIndex("TenantId", "SubjectId", "IsActive", "SortOrder")
                        .HasDatabaseName("ix_video_explanations_tenant_id_subject_id_is_active_sort_order");

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

            modelBuilder.Entity("Tiku.Domain.Content.VideoPlaybackProgress", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset?>("CompletedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("completed_at");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int?>("DurationSeconds")
                        .HasColumnType("integer")
                        .HasColumnName("duration_seconds");

                    b.Property<bool>("IsCompleted")
                        .HasColumnType("boolean")
                        .HasColumnName("is_completed");

                    b.Property<DateTimeOffset>("LastPlayedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("last_played_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("PlayCount")
                        .HasColumnType("integer")
                        .HasColumnName("play_count");

                    b.Property<int>("PositionSeconds")
                        .HasColumnType("integer")
                        .HasColumnName("position_seconds");

                    b.Property<Guid?>("QuestionId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.Property<Guid>("VideoId")
                        .HasColumnType("uuid")
                        .HasColumnName("video_id");

                    b.Property<int>("WatchedSeconds")
                        .HasColumnType("integer")
                        .HasColumnName("watched_seconds");

                    b.HasKey("Id")
                        .HasName("pk_video_playback_progress");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_video_playback_progress_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_video_playback_progress_user_id");

                    b.HasIndex("TenantId", "QuestionId")
                        .HasDatabaseName("ix_video_playback_progress_tenant_id_question_id");

                    b.HasIndex("TenantId", "VideoId")
                        .HasDatabaseName("ix_video_playback_progress_tenant_id_video_id");

                    b.HasIndex("TenantId", "UserId", "LastPlayedAt")
                        .HasDatabaseName("ix_video_playback_progress_tenant_id_user_id_last_played_at");

                    b.HasIndex("TenantId", "UserId", "VideoId")
                        .IsUnique()
                        .HasDatabaseName("ix_video_playback_progress_tenant_id_user_id_video_id")
                        .HasFilter("question_id is null");

                    b.HasIndex("TenantId", "UserId", "VideoId", "QuestionId")
                        .IsUnique()
                        .HasDatabaseName("ix_video_playback_progress_tenant_id_user_id_video_id_question~")
                        .HasFilter("question_id is not null");

                    b.ToTable("video_playback_progress", null, t =>
                        {
                            t.HasCheckConstraint("ck_video_playback_progress_duration", "duration_seconds is null or duration_seconds >= 0");

                            t.HasCheckConstraint("ck_video_playback_progress_play_count", "play_count >= 0");

                            t.HasCheckConstraint("ck_video_playback_progress_position", "position_seconds >= 0");

                            t.HasCheckConstraint("ck_video_playback_progress_watched", "watched_seconds >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Content.VocabularyUnit", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid?>("ContentNodeId")
                        .HasColumnType("uuid")
                        .HasColumnName("content_node_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<Guid?>("EntryId")
                        .HasColumnType("uuid")
                        .HasColumnName("entry_id");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("name");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("SourceHash")
                        .HasMaxLength(128)
                        .HasColumnType("character varying(128)")
                        .HasColumnName("source_hash");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int?>("WordCount")
                        .HasColumnType("integer")
                        .HasColumnName("word_count");

                    b.HasKey("Id")
                        .HasName("pk_vocabulary_units");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_vocabulary_units_tenant_id_id");

                    b.HasIndex("TenantId", "ContentNodeId")
                        .HasDatabaseName("ix_vocabulary_units_tenant_id_content_node_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_vocabulary_units_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_vocabulary_units_tenant_id_region_id");

                    b.HasIndex("TenantId", "EntryId", "ContentNodeId", "RegionId", "IsActive", "SortOrder")
                        .HasDatabaseName("ix_vocabulary_units_tenant_id_entry_id_content_node_id_region_~");

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

            modelBuilder.Entity("Tiku.Domain.Content.VocabularyWord", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid?>("ContentNodeId")
                        .HasColumnType("uuid")
                        .HasColumnName("content_node_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int?>("Difficulty")
                        .HasColumnType("integer")
                        .HasColumnName("difficulty");

                    b.Property<Guid?>("EntryId")
                        .HasColumnType("uuid")
                        .HasColumnName("entry_id");

                    b.Property<string>("Example")
                        .HasColumnType("text")
                        .HasColumnName("example");

                    b.Property<string>("ExampleTranslation")
                        .HasColumnType("text")
                        .HasColumnName("example_translation");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("Meaning")
                        .HasColumnType("text")
                        .HasColumnName("meaning");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Phonetic")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("phonetic");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("SourceHash")
                        .HasMaxLength(128)
                        .HasColumnType("character varying(128)")
                        .HasColumnName("source_hash");

                    b.Property<JsonElement>("Tags")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("tags")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<Guid?>("UnitId")
                        .HasColumnType("uuid")
                        .HasColumnName("unit_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Word")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("word");

                    b.HasKey("Id")
                        .HasName("pk_vocabulary_words");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_vocabulary_words_tenant_id_id");

                    b.HasIndex("TenantId", "ContentNodeId")
                        .HasDatabaseName("ix_vocabulary_words_tenant_id_content_node_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_vocabulary_words_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "UnitId", "IsActive", "SortOrder", "CreatedAt")
                        .HasDatabaseName("ix_vocabulary_words_tenant_id_unit_id_is_active_sort_order_cre~");

                    b.HasIndex("TenantId", "EntryId", "ContentNodeId", "UnitId", "IsActive", "SortOrder")
                        .HasDatabaseName("ix_vocabulary_words_tenant_id_entry_id_content_node_id_unit_id~");

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

            modelBuilder.Entity("Tiku.Domain.Growth.CommissionSettlement", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("CommissionAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("commission_amount_cents");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<decimal>("DefaultRate")
                        .HasPrecision(6, 4)
                        .HasColumnType("numeric(6,4)")
                        .HasColumnName("default_rate");

                    b.Property<decimal?>("EffectiveRate")
                        .HasPrecision(6, 4)
                        .HasColumnType("numeric(6,4)")
                        .HasColumnName("effective_rate");

                    b.Property<Guid?>("GeneratedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("generated_by");

                    b.Property<int>("GrossAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("gross_amount_cents");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset?>("PaidAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("paid_at");

                    b.Property<Guid?>("PaidBy")
                        .HasColumnType("uuid")
                        .HasColumnName("paid_by");

                    b.Property<int>("PaidUserCount")
                        .HasColumnType("integer")
                        .HasColumnName("paid_user_count");

                    b.Property<string>("PaymentAccount")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("payment_account");

                    b.Property<string>("PaymentMethod")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("payment_method");

                    b.Property<DateOnly>("PeriodEnd")
                        .HasColumnType("date")
                        .HasColumnName("period_end");

                    b.Property<DateOnly>("PeriodStart")
                        .HasColumnType("date")
                        .HasColumnName("period_start");

                    b.Property<Guid>("ReferrerUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("referrer_user_id");

                    b.Property<string>("Remark")
                        .HasColumnType("text")
                        .HasColumnName("remark");

                    b.Property<DateTimeOffset?>("ReviewedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("reviewed_at");

                    b.Property<Guid?>("ReviewedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("reviewed_by");

                    b.Property<string>("SettlementNo")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("settlement_no");

                    b.Property<int>("SourceCount")
                        .HasColumnType("integer")
                        .HasColumnName("source_count");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_commission_settlements");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_commission_settlements_tenant_id_id");

                    b.HasIndex("GeneratedBy")
                        .HasDatabaseName("ix_commission_settlements_generated_by");

                    b.HasIndex("PaidBy")
                        .HasDatabaseName("ix_commission_settlements_paid_by");

                    b.HasIndex("ReferrerUserId")
                        .HasDatabaseName("ix_commission_settlements_referrer_user_id");

                    b.HasIndex("ReviewedBy")
                        .HasDatabaseName("ix_commission_settlements_reviewed_by");

                    b.HasIndex("TenantId", "SettlementNo")
                        .IsUnique()
                        .HasDatabaseName("ix_commission_settlements_tenant_id_settlement_no");

                    b.HasIndex("TenantId", "ReferrerUserId", "PeriodStart")
                        .HasDatabaseName("ix_commission_settlements_referrer_start");

                    b.HasIndex("TenantId", "ReferrerUserId", "PeriodStart", "PeriodEnd")
                        .IsUnique()
                        .HasDatabaseName("ux_commission_settlements_referrer_period");

                    b.ToTable("commission_settlements", null, t =>
                        {
                            t.HasCheckConstraint("ck_commission_settlements_amounts", "gross_amount_cents >= 0 and commission_amount_cents >= 0");

                            t.HasCheckConstraint("ck_commission_settlements_counts", "source_count >= 0 and paid_user_count >= 0");

                            t.HasCheckConstraint("ck_commission_settlements_period", "period_end >= period_start");

                            t.HasCheckConstraint("ck_commission_settlements_rates", "default_rate >= 0 and default_rate <= 1 and (effective_rate is null or (effective_rate >= 0 and effective_rate <= 1))");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Growth.CommissionSettlementExportEvent", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("ContentSha256")
                        .HasMaxLength(128)
                        .HasColumnType("character varying(128)")
                        .HasColumnName("content_sha256");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("ExportFormat")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("export_format");

                    b.Property<Guid?>("ExportedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("exported_by");

                    b.Property<string>("Filename")
                        .IsRequired()
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("filename");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("RowCount")
                        .HasColumnType("integer")
                        .HasColumnName("row_count");

                    b.Property<Guid>("SettlementId")
                        .HasColumnType("uuid")
                        .HasColumnName("settlement_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.HasKey("Id")
                        .HasName("pk_commission_settlement_export_events");

                    b.HasIndex("ExportedBy")
                        .HasDatabaseName("ix_commission_settlement_export_events_exported_by");

                    b.HasIndex("TenantId", "SettlementId", "CreatedAt")
                        .HasDatabaseName("ix_commission_settlement_export_events_tenant_id_settlement_id~");

                    b.ToTable("commission_settlement_export_events", null, t =>
                        {
                            t.HasCheckConstraint("ck_commission_export_events_rows", "row_count >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Growth.CommissionSettlementItem", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("AttributionType")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("attribution_type");

                    b.Property<int>("CommissionAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("commission_amount_cents");

                    b.Property<decimal>("CommissionRate")
                        .HasPrecision(6, 4)
                        .HasColumnType("numeric(6,4)")
                        .HasColumnName("commission_rate");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int>("GrossAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("gross_amount_cents");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("RateSource")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("rate_source");

                    b.Property<Guid>("ReferrerUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("referrer_user_id");

                    b.Property<Guid?>("SettlementId")
                        .HasColumnType("uuid")
                        .HasColumnName("settlement_id");

                    b.Property<Guid>("SourceId")
                        .HasColumnType("uuid")
                        .HasColumnName("source_id");

                    b.Property<string>("SourceNo")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("source_no");

                    b.Property<DateTimeOffset?>("SourcePaidAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("source_paid_at");

                    b.Property<string>("SourceType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("source_type");

                    b.Property<Guid?>("StudentUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("student_user_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_commission_settlement_items");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_commission_settlement_items_tenant_id_id");

                    b.HasIndex("ReferrerUserId")
                        .HasDatabaseName("ix_commission_settlement_items_referrer_user_id");

                    b.HasIndex("StudentUserId")
                        .HasDatabaseName("ix_commission_settlement_items_student_user_id");

                    b.HasIndex("TenantId", "SettlementId")
                        .HasDatabaseName("ix_commission_settlement_items_tenant_id_settlement_id");

                    b.HasIndex("TenantId", "ReferrerUserId", "SourcePaidAt")
                        .HasDatabaseName("ix_commission_settlement_items_tenant_id_referrer_user_id_sour~");

                    b.HasIndex("TenantId", "SourceType", "SourceId")
                        .IsUnique()
                        .HasDatabaseName("ix_commission_settlement_items_tenant_id_source_type_source_id");

                    b.ToTable("commission_settlement_items", null, t =>
                        {
                            t.HasCheckConstraint("ck_commission_settlement_items_amounts", "gross_amount_cents >= 0 and commission_amount_cents >= 0");

                            t.HasCheckConstraint("ck_commission_settlement_items_rate", "commission_rate >= 0 and commission_rate <= 1");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Growth.CommissionSettlementProof", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int?>("AmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("amount_cents");

                    b.Property<Guid?>("AssetId")
                        .HasColumnType("uuid")
                        .HasColumnName("asset_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<string>("ExternalUrl")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("external_url");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset?>("PaidAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("paid_at");

                    b.Property<string>("PaymentAccount")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("payment_account");

                    b.Property<string>("PaymentMethod")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("payment_method");

                    b.Property<string>("ProofType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("proof_type");

                    b.Property<string>("ReviewNote")
                        .HasColumnType("text")
                        .HasColumnName("review_note");

                    b.Property<DateTimeOffset?>("ReviewedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("reviewed_at");

                    b.Property<Guid?>("ReviewedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("reviewed_by");

                    b.Property<Guid>("SettlementId")
                        .HasColumnType("uuid")
                        .HasColumnName("settlement_id");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid?>("SubmittedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("submitted_by");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Title")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("title");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_commission_settlement_proofs");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_commission_settlement_proofs_tenant_id_id");

                    b.HasIndex("ReviewedBy")
                        .HasDatabaseName("ix_commission_settlement_proofs_reviewed_by");

                    b.HasIndex("SubmittedBy")
                        .HasDatabaseName("ix_commission_settlement_proofs_submitted_by");

                    b.HasIndex("TenantId", "AssetId")
                        .HasDatabaseName("ix_commission_settlement_proofs_tenant_id_asset_id");

                    b.HasIndex("TenantId", "SettlementId", "Status", "CreatedAt")
                        .HasDatabaseName("ix_commission_settlement_proofs_tenant_id_settlement_id_status~");

                    b.ToTable("commission_settlement_proofs", null, t =>
                        {
                            t.HasCheckConstraint("ck_commission_settlement_proofs_amount", "amount_cents is null or amount_cents >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Growth.CrmConfig", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<JsonElement>("AssignmentConfig")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("assignment_config")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("AssignmentCursor")
                        .HasColumnType("integer")
                        .HasColumnName("assignment_cursor");

                    b.Property<string>("AssignmentMode")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("assignment_mode");

                    b.Property<JsonElement>("AssignmentPool")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("assignment_pool")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int?>("DelaySeconds")
                        .HasColumnType("integer")
                        .HasColumnName("delay_seconds");

                    b.Property<bool>("Enabled")
                        .HasColumnType("boolean")
                        .HasColumnName("enabled");

                    b.Property<string>("ExamType")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("exam_type");

                    b.Property<string>("FormName")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("form_name");

                    b.Property<string>("SecretRef")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("secret_ref");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<int?>("TimeoutSeconds")
                        .HasColumnType("integer")
                        .HasColumnName("timeout_seconds");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Url")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("url");

                    b.HasKey("Id")
                        .HasName("pk_crm_config");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_crm_config_tenant_id_id");

                    b.HasIndex("TenantId")
                        .IsUnique()
                        .HasDatabaseName("ix_crm_config_tenant_id");

                    b.HasIndex("TenantId", "AssignmentMode")
                        .HasDatabaseName("ix_crm_config_tenant_id_assignment_mode");

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

            modelBuilder.Entity("Tiku.Domain.Growth.CrmWebhookLog", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int?>("Attempt")
                        .HasColumnType("integer")
                        .HasColumnName("attempt");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("ErrorMessage")
                        .HasColumnType("text")
                        .HasColumnName("error_message");

                    b.Property<int?>("HttpCode")
                        .HasColumnType("integer")
                        .HasColumnName("http_code");

                    b.Property<string>("LeadId")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("lead_id");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("Outcome")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("outcome");

                    b.Property<string>("RecordId")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("record_id");

                    b.Property<string>("RequestBody")
                        .HasColumnType("text")
                        .HasColumnName("request_body");

                    b.Property<JsonElement>("RequestPayload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("request_payload")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("ResponseSummary")
                        .HasMaxLength(2000)
                        .HasColumnType("character varying(2000)")
                        .HasColumnName("response_summary");

                    b.Property<DateTimeOffset?>("SignedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("signed_at");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_crm_webhook_log");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_crm_webhook_log_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_crm_webhook_log_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RecordId", "CreatedAt")
                        .HasDatabaseName("ix_crm_webhook_log_tenant_id_record_id_created_at");

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

            modelBuilder.Entity("Tiku.Domain.Growth.CrmWebhookQueueItem", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("Attempts")
                        .HasColumnType("integer")
                        .HasColumnName("attempts");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("IdempotencyKey")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("idempotency_key");

                    b.Property<DateTimeOffset?>("LastAttemptAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("last_attempt_at");

                    b.Property<string>("LastError")
                        .HasColumnType("text")
                        .HasColumnName("last_error");

                    b.Property<int?>("LastHttpCode")
                        .HasColumnType("integer")
                        .HasColumnName("last_http_code");

                    b.Property<string>("LastResponseSummary")
                        .HasColumnType("text")
                        .HasColumnName("last_response_summary");

                    b.Property<string>("LeadId")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("lead_id");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<DateTimeOffset?>("NextAttemptAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("next_attempt_at");

                    b.Property<JsonElement>("Payload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("payload")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Provider")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("provider");

                    b.Property<string>("RecordId")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("record_id");

                    b.Property<DateTimeOffset?>("ScheduledAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("scheduled_at");

                    b.Property<DateTimeOffset?>("SentAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("sent_at");

                    b.Property<string>("Source")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("source");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<string>("TargetUrl")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("target_url");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_crm_webhook_queue");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_crm_webhook_queue_tenant_id_id");

                    b.HasIndex("TenantId", "IdempotencyKey")
                        .IsUnique()
                        .HasDatabaseName("ix_crm_webhook_queue_tenant_id_idempotency_key")
                        .HasFilter("idempotency_key is not null");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_crm_webhook_queue_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RecordId")
                        .IsUnique()
                        .HasDatabaseName("ix_crm_webhook_queue_tenant_id_record_id")
                        .HasFilter("record_id is not null");

                    b.HasIndex("TenantId", "RecordId", "CreatedAt")
                        .HasDatabaseName("ix_crm_webhook_queue_tenant_id_record_id_created_at")
                        .HasFilter("record_id is not null");

                    b.HasIndex("TenantId", "Source", "CreatedAt")
                        .HasDatabaseName("ix_crm_webhook_queue_tenant_id_source_created_at")
                        .HasFilter("source = 'tenant.student.crm_push'");

                    b.HasIndex("TenantId", "Status", "ScheduledAt", "NextAttemptAt")
                        .HasDatabaseName("ix_crm_webhook_queue_tenant_id_status_scheduled_at_next_attemp~");

                    b.ToTable("crm_webhook_queue", null, t =>
                        {
                            t.HasCheckConstraint("ck_crm_webhook_queue_attempts", "attempts >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Growth.ReferralCode", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Channel")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("channel");

                    b.Property<string>("Code")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("citext")
                        .HasColumnName("code");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("LandingPath")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("landing_path");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_referral_codes");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_referral_codes_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_referral_codes_user_id");

                    b.HasIndex("TenantId", "Code")
                        .IsUnique()
                        .HasDatabaseName("ix_referral_codes_tenant_id_code");

                    b.HasIndex("TenantId", "UserId")
                        .IsUnique()
                        .HasDatabaseName("ix_referral_codes_tenant_id_user_id");

                    b.HasIndex("TenantId", "Code", "Status")
                        .HasDatabaseName("ix_referral_codes_tenant_id_code_status");

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

            modelBuilder.Entity("Tiku.Domain.Growth.ReferralLead", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset?>("AssignedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("assigned_at");

                    b.Property<Guid?>("AssignedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("assigned_by");

                    b.Property<Guid?>("AssignedToUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("assigned_to_user_id");

                    b.Property<string>("AssignmentMode")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("assignment_mode");

                    b.Property<string>("BindType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("bind_type");

                    b.Property<DateTimeOffset>("BoundAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("bound_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("FirstTrackId")
                        .HasColumnType("uuid")
                        .HasColumnName("first_track_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset?>("ProtectedUntil")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("protected_until");

                    b.Property<string>("RefCode")
                        .HasMaxLength(100)
                        .HasColumnType("citext")
                        .HasColumnName("ref_code");

                    b.Property<Guid?>("ReferrerUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("referrer_user_id");

                    b.Property<string>("Source")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("source");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("StudentUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("student_user_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_referral_leads");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_referral_leads_tenant_id_id");

                    b.HasIndex("AssignedBy")
                        .HasDatabaseName("ix_referral_leads_assigned_by");

                    b.HasIndex("AssignedToUserId")
                        .HasDatabaseName("ix_referral_leads_assigned_to_user_id");

                    b.HasIndex("ReferrerUserId")
                        .HasDatabaseName("ix_referral_leads_referrer_user_id");

                    b.HasIndex("StudentUserId")
                        .HasDatabaseName("ix_referral_leads_student_user_id");

                    b.HasIndex("TenantId", "FirstTrackId")
                        .HasDatabaseName("ix_referral_leads_tenant_id_first_track_id");

                    b.HasIndex("TenantId", "StudentUserId")
                        .IsUnique()
                        .HasDatabaseName("ix_referral_leads_tenant_id_student_user_id");

                    b.HasIndex("TenantId", "ReferrerUserId", "BoundAt")
                        .HasDatabaseName("ix_referral_leads_tenant_id_referrer_user_id_bound_at");

                    b.HasIndex("TenantId", "AssignedToUserId", "Status", "BoundAt")
                        .HasDatabaseName("ix_referral_leads_tenant_id_assigned_to_user_id_status_bound_at");

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

            modelBuilder.Entity("Tiku.Domain.Growth.ReferralQrcode", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("ErrorMessage")
                        .HasColumnType("text")
                        .HasColumnName("error_message");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Page")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("page");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("provider");

                    b.Property<string>("QrcodeUrl")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("qrcode_url");

                    b.Property<string>("RefCode")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("citext")
                        .HasColumnName("ref_code");

                    b.Property<string>("Scene")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("scene");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_referral_qrcodes");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_referral_qrcodes_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_referral_qrcodes_user_id");

                    b.HasIndex("TenantId", "RefCode", "Status")
                        .HasDatabaseName("ix_referral_qrcodes_tenant_id_ref_code_status");

                    b.HasIndex("TenantId", "Provider", "Scene", "Page")
                        .IsUnique()
                        .HasDatabaseName("ix_referral_qrcodes_tenant_id_provider_scene_page");

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

            modelBuilder.Entity("Tiku.Domain.Growth.ReferralTeamEdge", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("LeaderUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("leader_user_id");

                    b.Property<Guid>("MemberUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("member_user_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("RelationType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("relation_type");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_referral_team_edges");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_referral_team_edges_tenant_id_id");

                    b.HasIndex("LeaderUserId")
                        .HasDatabaseName("ix_referral_team_edges_leader_user_id");

                    b.HasIndex("MemberUserId")
                        .HasDatabaseName("ix_referral_team_edges_member_user_id");

                    b.HasIndex("TenantId", "LeaderUserId", "Status")
                        .HasDatabaseName("ix_referral_team_edges_tenant_id_leader_user_id_status");

                    b.HasIndex("TenantId", "MemberUserId", "RelationType")
                        .IsUnique()
                        .HasDatabaseName("ix_referral_team_edges_tenant_id_member_user_id_relation_type");

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

            modelBuilder.Entity("Tiku.Domain.Growth.ReferralTrack", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("EventType")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("event_type");

                    b.Property<string>("IpAddress")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("ip_address");

                    b.Property<Guid?>("LeadId")
                        .HasColumnType("uuid")
                        .HasColumnName("lead_id");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("RefCode")
                        .HasMaxLength(100)
                        .HasColumnType("citext")
                        .HasColumnName("ref_code");

                    b.Property<Guid?>("ReferrerUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("referrer_user_id");

                    b.Property<string>("Source")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("source");

                    b.Property<Guid?>("TargetUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("target_user_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("UserAgent")
                        .HasMaxLength(1024)
                        .HasColumnType("character varying(1024)")
                        .HasColumnName("user_agent");

                    b.HasKey("Id")
                        .HasName("pk_referral_tracks");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_referral_tracks_tenant_id_id");

                    b.HasIndex("ReferrerUserId")
                        .HasDatabaseName("ix_referral_tracks_referrer_user_id");

                    b.HasIndex("TargetUserId")
                        .HasDatabaseName("ix_referral_tracks_target_user_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_referral_tracks_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "LeadId", "CreatedAt")
                        .HasDatabaseName("ix_referral_tracks_tenant_id_lead_id_created_at");

                    b.HasIndex("TenantId", "RefCode", "EventType", "CreatedAt")
                        .HasDatabaseName("ix_referral_tracks_tenant_id_ref_code_event_type_created_at");

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

            modelBuilder.Entity("Tiku.Domain.Growth.TenantCommissionSetting", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<JsonElement>("Config")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("config")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<decimal>("DefaultRate")
                        .HasPrecision(6, 4)
                        .HasColumnType("numeric(6,4)")
                        .HasColumnName("default_rate");

                    b.Property<int>("MinSettlementCents")
                        .HasColumnType("integer")
                        .HasColumnName("min_settlement_cents");

                    b.Property<string>("SettlementCycle")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("settlement_cycle");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UpdatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("updated_by");

                    b.HasKey("Id")
                        .HasName("pk_tenant_commission_settings");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_commission_settings_tenant_id_id");

                    b.HasIndex("TenantId")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_commission_settings_tenant_id");

                    b.HasIndex("UpdatedBy")
                        .HasDatabaseName("ix_tenant_commission_settings_updated_by");

                    b.ToTable("tenant_commission_settings", null, t =>
                        {
                            t.HasCheckConstraint("ck_tenant_commission_settings_default_rate", "default_rate >= 0 and default_rate <= 1");

                            t.HasCheckConstraint("ck_tenant_commission_settings_min_settlement", "min_settlement_cents >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Identity.StudentProfile", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("AvatarPreset")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasDefaultValue("male")
                        .HasColumnName("avatar_preset");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateOnly?>("LastCheckInDate")
                        .HasColumnType("date")
                        .HasColumnName("last_check_in_date");

                    b.Property<string>("LegacyUserId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_user_id");

                    b.Property<int>("MasteredWordsCount")
                        .HasColumnType("integer")
                        .HasColumnName("mastered_words_count");

                    b.Property<JsonElement>("ModuleSelections")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("module_selections")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<JsonElement>("Progress")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("progress")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("QuestionsAnsweredToday")
                        .HasColumnType("integer")
                        .HasColumnName("questions_answered_today");

                    b.Property<JsonElement>("RecentActivities")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("recent_activities")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<Guid?>("SelectedMajorId")
                        .HasColumnType("uuid")
                        .HasColumnName("selected_major_id");

                    b.Property<Guid?>("SelectedSchoolId")
                        .HasColumnType("uuid")
                        .HasColumnName("selected_school_id");

                    b.Property<JsonElement>("Stats")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("stats")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_student_profiles");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_student_profiles_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_student_profiles_user_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_student_profiles_tenant_id_region_id");

                    b.HasIndex("TenantId", "SelectedMajorId")
                        .HasDatabaseName("ix_student_profiles_tenant_id_selected_major_id");

                    b.HasIndex("TenantId", "SelectedSchoolId")
                        .HasDatabaseName("ix_student_profiles_tenant_id_selected_school_id");

                    b.HasIndex("TenantId", "UserId")
                        .IsUnique()
                        .HasDatabaseName("ix_student_profiles_tenant_id_user_id");

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

            modelBuilder.Entity("Tiku.Domain.Identity.User", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("AccessFailedCount")
                        .HasColumnType("integer")
                        .HasColumnName("access_failed_count");

                    b.Property<string>("AvatarUrl")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("avatar_url");

                    b.Property<string>("ConcurrencyStamp")
                        .IsConcurrencyToken()
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("concurrency_stamp");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Email")
                        .HasMaxLength(320)
                        .HasColumnType("citext")
                        .HasColumnName("email");

                    b.Property<bool>("EmailConfirmed")
                        .HasColumnType("boolean")
                        .HasColumnName("email_confirmed");

                    b.Property<bool>("ForcePasswordChange")
                        .HasColumnType("boolean")
                        .HasColumnName("force_password_change");

                    b.Property<DateTimeOffset?>("LastSeenAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("last_seen_at");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<bool>("LockoutEnabled")
                        .HasColumnType("boolean")
                        .HasColumnName("lockout_enabled");

                    b.Property<DateTimeOffset?>("LockoutEnd")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("lockout_end");

                    b.Property<string>("Name")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<string>("NormalizedEmail")
                        .HasMaxLength(320)
                        .HasColumnType("character varying(320)")
                        .HasColumnName("normalized_email");

                    b.Property<string>("NormalizedUserName")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("normalized_user_name");

                    b.Property<string>("PasswordHash")
                        .HasMaxLength(1024)
                        .HasColumnType("character varying(1024)")
                        .HasColumnName("password_hash");

                    b.Property<string>("Phone")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("phone");

                    b.Property<string>("PhoneNumber")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("phone_number");

                    b.Property<bool>("PhoneNumberConfirmed")
                        .HasColumnType("boolean")
                        .HasColumnName("phone_number_confirmed");

                    b.Property<string>("PrimaryRole")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("primary_role");

                    b.Property<JsonElement>("RawProfile")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("raw_profile")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("Score")
                        .HasColumnType("integer")
                        .HasColumnName("score");

                    b.Property<string>("SecurityStamp")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("security_stamp");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<bool>("TwoFactorEnabled")
                        .HasColumnType("boolean")
                        .HasColumnName("two_factor_enabled");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("UserName")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("user_name");

                    b.HasKey("Id")
                        .HasName("pk_users");

                    b.HasIndex("LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_users_legacy_id");

                    b.HasIndex("NormalizedEmail")
                        .HasDatabaseName("email_index");

                    b.HasIndex("NormalizedUserName")
                        .IsUnique()
                        .HasDatabaseName("user_name_index");

                    b.HasIndex("Phone")
                        .IsUnique()
                        .HasDatabaseName("ix_users_phone");

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

            modelBuilder.Entity("Tiku.Domain.Identity.UserIdentity", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Email")
                        .HasMaxLength(320)
                        .HasColumnType("citext")
                        .HasColumnName("email");

                    b.Property<string>("OpenId")
                        .HasMaxLength(255)
                        .HasColumnType("character varying(255)")
                        .HasColumnName("open_id");

                    b.Property<string>("Phone")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("phone");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("provider");

                    b.Property<string>("ProviderSubject")
                        .IsRequired()
                        .HasMaxLength(255)
                        .HasColumnType("character varying(255)")
                        .HasColumnName("provider_subject");

                    b.Property<string>("UnionId")
                        .HasMaxLength(255)
                        .HasColumnType("character varying(255)")
                        .HasColumnName("union_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_user_identities");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_user_identities_user_id");

                    b.HasIndex("Provider", "ProviderSubject")
                        .IsUnique()
                        .HasDatabaseName("ix_user_identities_provider_provider_subject");

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

            modelBuilder.Entity("Tiku.Domain.Import.PocketBaseImportIssue", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("CollectionName")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("collection_name");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("FieldPath")
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("field_path");

                    b.Property<string>("IssueCode")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("issue_code");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("Message")
                        .IsRequired()
                        .HasColumnType("text")
                        .HasColumnName("message");

                    b.Property<string>("RawValueSample")
                        .HasMaxLength(2000)
                        .HasColumnType("character varying(2000)")
                        .HasColumnName("raw_value_sample");

                    b.Property<Guid?>("RunId")
                        .HasColumnType("uuid")
                        .HasColumnName("run_id");

                    b.Property<string>("Severity")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("severity");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.HasKey("Id")
                        .HasName("pk_pb_import_issues");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_pb_import_issues_tenant_id_id");

                    b.HasIndex("TenantId", "RunId")
                        .HasDatabaseName("ix_pb_import_issues_tenant_id_run_id");

                    b.HasIndex("RunId", "Severity", "CollectionName")
                        .HasDatabaseName("ix_pb_import_issues_run_id_severity_collection_name");

                    b.HasIndex("TenantId", "CollectionName", "LegacyId")
                        .HasDatabaseName("ix_pb_import_issues_tenant_id_collection_name_legacy_id");

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

            modelBuilder.Entity("Tiku.Domain.Import.PocketBaseImportRun", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset?>("FinishedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("finished_at");

                    b.Property<string>("SourceKind")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("source_kind");

                    b.Property<string>("SourceName")
                        .IsRequired()
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("source_name");

                    b.Property<DateTimeOffset>("StartedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("started_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("Stats")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("stats")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.HasKey("Id")
                        .HasName("pk_pb_import_runs");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_pb_import_runs_tenant_id_id");

                    b.HasIndex("TenantId", "Status", "StartedAt")
                        .HasDatabaseName("ix_pb_import_runs_tenant_id_status_started_at");

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

            modelBuilder.Entity("Tiku.Domain.Import.PocketBaseRawRecord", b =>
                {
                    b.Property<Guid>("RunId")
                        .HasColumnType("uuid")
                        .HasColumnName("run_id");

                    b.Property<string>("CollectionName")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("collection_name");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Errors")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("errors")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<DateTimeOffset>("ImportedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("imported_at")
                        .HasDefaultValueSql("now()");

                    b.Property<bool>("Normalized")
                        .HasColumnType("boolean")
                        .HasColumnName("normalized");

                    b.Property<JsonElement>("Record")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("record")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.HasKey("RunId", "CollectionName", "LegacyId")
                        .HasName("pk_pb_raw_records");

                    b.HasIndex("TenantId", "RunId")
                        .HasDatabaseName("ix_pb_raw_records_tenant_id_run_id");

                    b.HasIndex("TenantId", "CollectionName", "LegacyId")
                        .HasDatabaseName("ix_pb_raw_records_tenant_id_collection_name_legacy_id");

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

            modelBuilder.Entity("Tiku.Domain.Learning.AnswerRecord", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("AnswerText")
                        .HasColumnType("text")
                        .HasColumnName("answer_text");

                    b.Property<DateTimeOffset>("AnsweredAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("answered_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<bool?>("IsCorrect")
                        .HasColumnType("boolean")
                        .HasColumnName("is_correct");

                    b.Property<string>("LegacyCategoryId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_category_id");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("LegacyQuestionId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_question_id");

                    b.Property<Guid>("PracticeSessionId")
                        .HasColumnType("uuid")
                        .HasColumnName("practice_session_id");

                    b.Property<JsonElement>("SelectedOptions")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("selected_options")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<Guid>("SessionQuestionId")
                        .HasColumnType("uuid")
                        .HasColumnName("session_question_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_answer_records");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_answer_records_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_answer_records_user_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_answer_records_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "PracticeSessionId", "SessionQuestionId")
                        .HasDatabaseName("ix_answer_records_tenant_id_practice_session_id_session_questi~");

                    b.HasIndex("TenantId", "UserId", "PracticeSessionId")
                        .HasDatabaseName("ix_answer_records_tenant_id_user_id_practice_session_id");

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

            modelBuilder.Entity("Tiku.Domain.Learning.DashboardDailyStat", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("ActiveUsers")
                        .HasColumnType("integer")
                        .HasColumnName("active_users");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("LegacyRegionId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_region_id");

                    b.Property<int>("NewOrders")
                        .HasColumnType("integer")
                        .HasColumnName("new_orders");

                    b.Property<int>("NewQuestions")
                        .HasColumnType("integer")
                        .HasColumnName("new_questions");

                    b.Property<int>("NewRevenueCents")
                        .HasColumnType("integer")
                        .HasColumnName("new_revenue_cents");

                    b.Property<int>("NewUsers")
                        .HasColumnType("integer")
                        .HasColumnName("new_users");

                    b.Property<DateTimeOffset?>("RebuiltAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("rebuilt_at");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<DateOnly>("StatDate")
                        .HasColumnType("date")
                        .HasColumnName("stat_date");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_dashboard_daily_stats");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_dashboard_daily_stats_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_dashboard_daily_stats_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_dashboard_daily_stats_tenant_id_region_id");

                    b.HasIndex("TenantId", "StatDate", "RegionId")
                        .IsUnique()
                        .HasDatabaseName("ix_dashboard_daily_stats_tenant_id_stat_date_region_id");

                    NpgsqlIndexBuilderExtensions.AreNullsDistinct(b.HasIndex("TenantId", "StatDate", "RegionId"), false);

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

            modelBuilder.Entity("Tiku.Domain.Learning.ExamDate", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<DateTimeOffset?>("ExamAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("exam_at");

                    b.Property<string>("ExamName")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("exam_name");

                    b.Property<string>("ExamType")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("exam_type");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<Guid?>("SchoolId")
                        .HasColumnType("uuid")
                        .HasColumnName("school_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_exam_dates");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_exam_dates_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_exam_dates_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_exam_dates_tenant_id_region_id");

                    b.HasIndex("TenantId", "SchoolId", "ExamAt")
                        .HasDatabaseName("ix_exam_dates_tenant_id_school_id_exam_at");

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

            modelBuilder.Entity("Tiku.Domain.Learning.FavoriteQuestion", b =>
                {
                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.Property<Guid>("QuestionReferenceId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_reference_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("QuestionId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_id");

                    b.Property<Guid>("QuestionOwnerTenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_owner_tenant_id");

                    b.Property<string>("Source")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("source");

                    b.HasKey("TenantId", "UserId", "QuestionReferenceId")
                        .HasName("pk_favorite_questions");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_favorite_questions_user_id");

                    b.HasIndex("QuestionOwnerTenantId", "QuestionId")
                        .HasDatabaseName("ix_favorite_questions_question_owner_tenant_id_question_id");

                    b.HasIndex("TenantId", "QuestionReferenceId")
                        .HasDatabaseName("ix_favorite_questions_tenant_id_question_reference_id");

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

            modelBuilder.Entity("Tiku.Domain.Learning.PracticeAccessEvent", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("AccessMode")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("access_mode");

                    b.Property<int>("ConsumedFreeQuota")
                        .HasColumnType("integer")
                        .HasColumnName("consumed_free_quota");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("EntitlementId")
                        .HasColumnType("uuid")
                        .HasColumnName("entitlement_id");

                    b.Property<string>("EventType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("event_type");

                    b.Property<int>("GrantedCount")
                        .HasColumnType("integer")
                        .HasColumnName("granted_count");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid?>("PracticeSessionId")
                        .HasColumnType("uuid")
                        .HasColumnName("practice_session_id");

                    b.Property<string>("Reason")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("reason");

                    b.Property<int>("RequestedCount")
                        .HasColumnType("integer")
                        .HasColumnName("requested_count");

                    b.Property<Guid?>("ScopeId")
                        .HasColumnType("uuid")
                        .HasColumnName("scope_id");

                    b.Property<string>("ScopeType")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("scope_type");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<Guid?>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_practice_access_events");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_practice_access_events_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_practice_access_events_user_id");

                    b.HasIndex("TenantId", "PracticeSessionId")
                        .HasDatabaseName("ix_practice_access_events_tenant_id_practice_session_id");

                    b.HasIndex("TenantId", "UserId", "CreatedAt")
                        .HasDatabaseName("ix_practice_access_events_tenant_id_user_id_created_at");

                    b.ToTable("practice_access_events", null, t =>
                        {
                            t.HasCheckConstraint("ck_practice_access_events_consumed_free_quota", "consumed_free_quota >= 0");

                            t.HasCheckConstraint("ck_practice_access_events_granted_count", "granted_count >= 0");

                            t.HasCheckConstraint("ck_practice_access_events_requested_count", "requested_count >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Learning.PracticeDailyUsage", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int>("FreeLimit")
                        .HasColumnType("integer")
                        .HasColumnName("free_limit");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid?>("ScopeId")
                        .HasColumnType("uuid")
                        .HasColumnName("scope_id");

                    b.Property<string>("ScopeType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("scope_type");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateOnly>("UsageDate")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("date")
                        .HasColumnName("usage_date")
                        .HasDefaultValueSql("current_date");

                    b.Property<int>("UsedCount")
                        .HasColumnType("integer")
                        .HasColumnName("used_count");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_practice_daily_usage");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_practice_daily_usage_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_practice_daily_usage_user_id");

                    b.HasIndex("TenantId", "UserId", "UsageDate")
                        .HasDatabaseName("ix_practice_daily_usage_tenant_id_user_id_usage_date");

                    b.HasIndex("TenantId", "UserId", "UsageDate", "ScopeType", "ScopeId")
                        .IsUnique()
                        .HasDatabaseName("ix_practice_daily_usage_tenant_id_user_id_usage_date_scope_typ~");

                    NpgsqlIndexBuilderExtensions.AreNullsDistinct(b.HasIndex("TenantId", "UserId", "UsageDate", "ScopeType", "ScopeId"), false);

                    b.ToTable("practice_daily_usage", null, t =>
                        {
                            t.HasCheckConstraint("ck_practice_daily_usage_free_limit", "free_limit >= 0");

                            t.HasCheckConstraint("ck_practice_daily_usage_used_count", "used_count >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Learning.PracticeSession", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid?>("AccessEntitlementId")
                        .HasColumnType("uuid")
                        .HasColumnName("access_entitlement_id");

                    b.Property<string>("AccessMode")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasDefaultValue("free")
                        .HasColumnName("access_mode");

                    b.Property<JsonElement>("AccessSnapshot")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("access_snapshot")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid?>("BlueprintId")
                        .HasColumnType("uuid")
                        .HasColumnName("blueprint_id");

                    b.Property<Guid?>("CollectionId")
                        .HasColumnType("uuid")
                        .HasColumnName("collection_id");

                    b.Property<int>("ConsumedFreeQuota")
                        .HasColumnType("integer")
                        .HasColumnName("consumed_free_quota");

                    b.Property<Guid?>("ContentNodeId")
                        .HasColumnType("uuid")
                        .HasColumnName("content_node_id");

                    b.Property<int?>("DurationMinutes")
                        .HasColumnType("integer")
                        .HasColumnName("duration_minutes");

                    b.Property<Guid?>("EntryId")
                        .HasColumnType("uuid")
                        .HasColumnName("entry_id");

                    b.Property<DateTimeOffset?>("ExpiresAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("expires_at");

                    b.Property<DateTimeOffset?>("FinishedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("finished_at");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Mode")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("mode");

                    b.Property<int>("QuestionCount")
                        .HasColumnType("integer")
                        .HasColumnName("question_count");

                    b.Property<DateTimeOffset>("StartedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("started_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("TargetId")
                        .HasColumnType("uuid")
                        .HasColumnName("target_id");

                    b.Property<string>("TargetType")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("target_type");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<decimal?>("TotalScore")
                        .HasPrecision(8, 2)
                        .HasColumnType("numeric(8,2)")
                        .HasColumnName("total_score");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_practice_sessions");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_practice_sessions_tenant_id_id");

                    b.HasAlternateKey("TenantId", "UserId", "Id")
                        .HasName("ak_practice_sessions_tenant_id_user_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_practice_sessions_user_id");

                    b.HasIndex("TenantId", "BlueprintId")
                        .HasDatabaseName("ix_practice_sessions_tenant_id_blueprint_id");

                    b.HasIndex("TenantId", "CollectionId")
                        .HasDatabaseName("ix_practice_sessions_tenant_id_collection_id");

                    b.HasIndex("TenantId", "ContentNodeId")
                        .HasDatabaseName("ix_practice_sessions_tenant_id_content_node_id");

                    b.HasIndex("TenantId", "EntryId")
                        .HasDatabaseName("ix_practice_sessions_tenant_id_entry_id");

                    b.HasIndex("TenantId", "UserId", "StartedAt")
                        .HasDatabaseName("ix_practice_sessions_tenant_id_user_id_started_at");

                    b.ToTable("practice_sessions", null, t =>
                        {
                            t.HasCheckConstraint("ck_practice_sessions_consumed_free_quota", "consumed_free_quota >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Learning.PracticeSessionQuestion", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("Position")
                        .HasColumnType("integer")
                        .HasColumnName("position");

                    b.Property<Guid>("PracticeSessionId")
                        .HasColumnType("uuid")
                        .HasColumnName("practice_session_id");

                    b.Property<Guid>("QuestionId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_id");

                    b.Property<Guid>("QuestionOwnerTenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_owner_tenant_id");

                    b.Property<Guid>("QuestionReferenceId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_reference_id");

                    b.Property<Guid>("QuestionVersionId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_version_id");

                    b.Property<decimal?>("Score")
                        .HasPrecision(8, 2)
                        .HasColumnType("numeric(8,2)")
                        .HasColumnName("score");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.HasKey("Id")
                        .HasName("pk_practice_session_questions");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_practice_session_questions_tenant_id_id");

                    b.HasAlternateKey("TenantId", "PracticeSessionId", "Id")
                        .HasName("ak_practice_session_questions_tenant_id_practice_session_id_id");

                    b.HasIndex("QuestionOwnerTenantId", "QuestionId", "QuestionVersionId")
                        .HasDatabaseName("ix_practice_session_questions_question_owner_tenant_id_questio~");

                    b.HasIndex("TenantId", "PracticeSessionId", "Position")
                        .IsUnique()
                        .HasDatabaseName("ix_practice_session_questions_tenant_id_practice_session_id_po~");

                    b.HasIndex("TenantId", "QuestionOwnerTenantId", "QuestionId")
                        .HasDatabaseName("ix_practice_session_questions_tenant_id_question_owner_tenant_~");

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

            modelBuilder.Entity("Tiku.Domain.Learning.PracticeSessionReport", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<decimal>("Accuracy")
                        .HasPrecision(6, 4)
                        .HasColumnType("numeric(6,4)")
                        .HasColumnName("accuracy");

                    b.Property<int>("AnsweredCount")
                        .HasColumnType("integer")
                        .HasColumnName("answered_count");

                    b.Property<Guid?>("BlueprintId")
                        .HasColumnType("uuid")
                        .HasColumnName("blueprint_id");

                    b.Property<Guid?>("CollectionId")
                        .HasColumnType("uuid")
                        .HasColumnName("collection_id");

                    b.Property<int>("CorrectCount")
                        .HasColumnType("integer")
                        .HasColumnName("correct_count");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int>("DurationSeconds")
                        .HasColumnType("integer")
                        .HasColumnName("duration_seconds");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Mode")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("mode");

                    b.Property<Guid>("PracticeSessionId")
                        .HasColumnType("uuid")
                        .HasColumnName("practice_session_id");

                    b.Property<JsonElement>("QuestionResults")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("question_results")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<decimal>("Score")
                        .HasPrecision(10, 2)
                        .HasColumnType("numeric(10,2)")
                        .HasColumnName("score");

                    b.Property<JsonElement>("SectionStats")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("section_stats")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<DateTimeOffset?>("StartedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("started_at");

                    b.Property<DateTimeOffset>("SubmittedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("submitted_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<int>("TotalQuestions")
                        .HasColumnType("integer")
                        .HasColumnName("total_questions");

                    b.Property<decimal>("TotalScore")
                        .HasPrecision(10, 2)
                        .HasColumnType("numeric(10,2)")
                        .HasColumnName("total_score");

                    b.Property<int>("UnansweredCount")
                        .HasColumnType("integer")
                        .HasColumnName("unanswered_count");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.Property<int>("WrongCount")
                        .HasColumnType("integer")
                        .HasColumnName("wrong_count");

                    b.Property<JsonElement>("WrongQuestionIds")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("wrong_question_ids")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.HasKey("Id")
                        .HasName("pk_practice_session_reports");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_practice_session_reports_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_practice_session_reports_user_id");

                    b.HasIndex("TenantId", "CollectionId")
                        .HasDatabaseName("ix_practice_session_reports_tenant_id_collection_id");

                    b.HasIndex("TenantId", "PracticeSessionId")
                        .IsUnique()
                        .HasDatabaseName("ix_practice_session_reports_tenant_id_practice_session_id");

                    b.HasIndex("TenantId", "BlueprintId", "SubmittedAt")
                        .HasDatabaseName("ix_practice_session_reports_tenant_id_blueprint_id_submitted_at")
                        .HasFilter("blueprint_id is not null");

                    b.HasIndex("TenantId", "UserId", "SubmittedAt")
                        .HasDatabaseName("ix_practice_session_reports_tenant_id_user_id_submitted_at");

                    b.ToTable("practice_session_reports", null, t =>
                        {
                            t.HasCheckConstraint("ck_practice_session_reports_accuracy", "accuracy >= 0 and accuracy <= 1");

                            t.HasCheckConstraint("ck_practice_session_reports_counts", "total_questions >= 0 and answered_count >= 0 and correct_count >= 0 and wrong_count >= 0 and unanswered_count >= 0");

                            t.HasCheckConstraint("ck_practice_session_reports_duration", "duration_seconds >= 0");

                            t.HasCheckConstraint("ck_practice_session_reports_scores", "score >= 0 and total_score >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Learning.PracticeSessionReportSection", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<decimal>("Accuracy")
                        .HasPrecision(6, 4)
                        .HasColumnType("numeric(6,4)")
                        .HasColumnName("accuracy");

                    b.Property<int>("AnsweredCount")
                        .HasColumnType("integer")
                        .HasColumnName("answered_count");

                    b.Property<int>("CorrectCount")
                        .HasColumnType("integer")
                        .HasColumnName("correct_count");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid>("PracticeSessionId")
                        .HasColumnType("uuid")
                        .HasColumnName("practice_session_id");

                    b.Property<int>("QuestionCount")
                        .HasColumnType("integer")
                        .HasColumnName("question_count");

                    b.Property<string>("QuestionType")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("question_type");

                    b.Property<Guid>("ReportId")
                        .HasColumnType("uuid")
                        .HasColumnName("report_id");

                    b.Property<decimal>("Score")
                        .HasPrecision(10, 2)
                        .HasColumnType("numeric(10,2)")
                        .HasColumnName("score");

                    b.Property<string>("SectionKey")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("section_key");

                    b.Property<string>("SectionName")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("section_name");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<decimal>("TotalScore")
                        .HasPrecision(10, 2)
                        .HasColumnType("numeric(10,2)")
                        .HasColumnName("total_score");

                    b.Property<int>("UnansweredCount")
                        .HasColumnType("integer")
                        .HasColumnName("unanswered_count");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int>("WrongCount")
                        .HasColumnType("integer")
                        .HasColumnName("wrong_count");

                    b.HasKey("Id")
                        .HasName("pk_practice_session_report_sections");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_practice_session_report_sections_tenant_id_id");

                    b.HasIndex("TenantId", "PracticeSessionId")
                        .HasDatabaseName("ix_practice_session_report_sections_tenant_id_practice_session~");

                    b.HasIndex("TenantId", "ReportId", "SectionKey")
                        .IsUnique()
                        .HasDatabaseName("ix_practice_session_report_sections_tenant_id_report_id_sectio~");

                    b.HasIndex("TenantId", "ReportId", "SortOrder")
                        .HasDatabaseName("ix_practice_session_report_sections_tenant_id_report_id_sort_o~");

                    b.ToTable("practice_session_report_sections", null, t =>
                        {
                            t.HasCheckConstraint("ck_practice_session_report_sections_accuracy", "accuracy >= 0 and accuracy <= 1");

                            t.HasCheckConstraint("ck_practice_session_report_sections_counts", "question_count >= 0 and answered_count >= 0 and correct_count >= 0 and wrong_count >= 0 and unanswered_count >= 0");

                            t.HasCheckConstraint("ck_practice_session_report_sections_scores", "score >= 0 and total_score >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Learning.RecentPractice", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Color")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("color");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset?>("LastAccessAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("last_access_at");

                    b.Property<DateTimeOffset?>("LastPracticeAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("last_practice_at");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("PracticeType")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("practice_type");

                    b.Property<int>("Progress")
                        .HasColumnType("integer")
                        .HasColumnName("progress");

                    b.Property<string>("TargetLegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("target_legacy_id");

                    b.Property<string>("TargetName")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("target_name");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_recent_practices");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_recent_practices_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_recent_practices_user_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_recent_practices_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "UserId", "LastAccessAt")
                        .HasDatabaseName("ix_recent_practices_tenant_id_user_id_last_access_at");

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

            modelBuilder.Entity("Tiku.Domain.Learning.Report", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<JsonElement>("Attachments")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("attachments")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<string>("Category")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("category");

                    b.Property<string>("Contact")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("contact");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<DateTimeOffset?>("HandledAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("handled_at");

                    b.Property<Guid?>("HandledBy")
                        .HasColumnType("uuid")
                        .HasColumnName("handled_by");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Priority")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("priority");

                    b.Property<Guid?>("QuestionId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_id");

                    b.Property<string>("Resolution")
                        .HasColumnType("text")
                        .HasColumnName("resolution");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Title")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("title");

                    b.Property<string>("Type")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("type");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_reports");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_reports_tenant_id_id");

                    b.HasIndex("HandledBy")
                        .HasDatabaseName("ix_reports_handled_by");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_reports_user_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_reports_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "QuestionId", "CreatedAt")
                        .HasDatabaseName("ix_reports_tenant_id_question_id_created_at")
                        .HasFilter("question_id is not null");

                    b.HasIndex("TenantId", "Status", "CreatedAt")
                        .HasDatabaseName("ix_reports_tenant_id_status_created_at");

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

            modelBuilder.Entity("Tiku.Domain.Learning.ReportStatusEvent", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid?>("ActorUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("actor_user_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("FromStatus")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("from_status");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Note")
                        .HasColumnType("text")
                        .HasColumnName("note");

                    b.Property<Guid>("ReportId")
                        .HasColumnType("uuid")
                        .HasColumnName("report_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("ToStatus")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("to_status");

                    b.HasKey("Id")
                        .HasName("pk_report_status_events");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_report_status_events_tenant_id_id");

                    b.HasIndex("ActorUserId")
                        .HasDatabaseName("ix_report_status_events_actor_user_id");

                    b.HasIndex("TenantId", "ReportId", "CreatedAt")
                        .HasDatabaseName("ix_report_status_events_tenant_id_report_id_created_at");

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

            modelBuilder.Entity("Tiku.Domain.Learning.RevenueDailyStat", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("CodeCount")
                        .HasColumnType("integer")
                        .HasColumnName("code_count");

                    b.Property<int>("CodeEstimated")
                        .HasColumnType("integer")
                        .HasColumnName("code_estimated");

                    b.Property<int>("CodeUsed")
                        .HasColumnType("integer")
                        .HasColumnName("code_used");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int>("EstimatedRevenueCents")
                        .HasColumnType("integer")
                        .HasColumnName("estimated_revenue_cents");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("LegacyRegionId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_region_id");

                    b.Property<int>("OrderCount")
                        .HasColumnType("integer")
                        .HasColumnName("order_count");

                    b.Property<int>("RealRevenueCents")
                        .HasColumnType("integer")
                        .HasColumnName("real_revenue_cents");

                    b.Property<DateTimeOffset?>("RebuiltAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("rebuilt_at");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<string>("SaleType")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("sale_type");

                    b.Property<DateOnly>("StatDate")
                        .HasColumnType("date")
                        .HasColumnName("stat_date");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_revenue_daily_stats");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_revenue_daily_stats_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_revenue_daily_stats_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_revenue_daily_stats_tenant_id_region_id");

                    b.HasIndex("TenantId", "StatDate", "RegionId", "SaleType")
                        .IsUnique()
                        .HasDatabaseName("ix_revenue_daily_stats_tenant_id_stat_date_region_id_sale_type");

                    NpgsqlIndexBuilderExtensions.AreNullsDistinct(b.HasIndex("TenantId", "StatDate", "RegionId", "SaleType"), false);

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

            modelBuilder.Entity("Tiku.Domain.Learning.UserScoreEvent", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("BalanceAfter")
                        .HasColumnType("integer")
                        .HasColumnName("balance_after");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("EventType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("event_type");

                    b.Property<string>("IdempotencyKey")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("idempotency_key");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("Points")
                        .HasColumnType("integer")
                        .HasColumnName("points");

                    b.Property<Guid?>("SourceId")
                        .HasColumnType("uuid")
                        .HasColumnName("source_id");

                    b.Property<string>("SourceType")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("source_type");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_user_score_events");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_user_score_events_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_user_score_events_user_id");

                    b.HasIndex("TenantId", "IdempotencyKey")
                        .IsUnique()
                        .HasDatabaseName("ix_user_score_events_tenant_id_idempotency_key");

                    b.HasIndex("TenantId", "UserId", "CreatedAt")
                        .HasDatabaseName("ix_user_score_events_tenant_id_user_id_created_at");

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

            modelBuilder.Entity("Tiku.Domain.Learning.WrongQuestion", b =>
                {
                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.Property<Guid>("QuestionReferenceId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_reference_id");

                    b.Property<DateTimeOffset>("LastWrongAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("last_wrong_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("QuestionId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_id");

                    b.Property<Guid>("QuestionOwnerTenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_owner_tenant_id");

                    b.Property<DateTimeOffset?>("ResolvedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("resolved_at");

                    b.Property<int>("WrongCount")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("integer")
                        .HasDefaultValue(1)
                        .HasColumnName("wrong_count");

                    b.HasKey("TenantId", "UserId", "QuestionReferenceId")
                        .HasName("pk_wrong_questions");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_wrong_questions_user_id");

                    b.HasIndex("QuestionOwnerTenantId", "QuestionId")
                        .HasDatabaseName("ix_wrong_questions_question_owner_tenant_id_question_id");

                    b.HasIndex("TenantId", "QuestionReferenceId")
                        .HasDatabaseName("ix_wrong_questions_tenant_id_question_reference_id");

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

            modelBuilder.Entity("Tiku.Domain.Operations.Announcement", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("BackgroundColor")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("background_color");

                    b.Property<string>("Content")
                        .HasColumnType("text")
                        .HasColumnName("content");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("Link")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("link");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_announcements");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_announcements_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_announcements_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "IsActive", "SortOrder")
                        .HasDatabaseName("ix_announcements_tenant_id_is_active_sort_order");

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

            modelBuilder.Entity("Tiku.Domain.Operations.AuditLog", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Action")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("action");

                    b.Property<Guid?>("ActorUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("actor_user_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("Details")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("details")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("IpAddress")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("ip_address");

                    b.Property<string>("TargetId")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("target_id");

                    b.Property<string>("TargetType")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("target_type");

                    b.Property<Guid?>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("UserAgent")
                        .HasMaxLength(1024)
                        .HasColumnType("character varying(1024)")
                        .HasColumnName("user_agent");

                    b.HasKey("Id")
                        .HasName("pk_audit_logs");

                    b.HasIndex("ActorUserId")
                        .HasDatabaseName("ix_audit_logs_actor_user_id");

                    b.HasIndex("TenantId", "CreatedAt")
                        .HasDatabaseName("ix_audit_logs_tenant_id_created_at");

                    b.HasIndex("TenantId", "TargetType", "TargetId", "CreatedAt")
                        .HasDatabaseName("ix_audit_logs_tenant_id_target_type_target_id_created_at");

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

            modelBuilder.Entity("Tiku.Domain.Operations.BackendMenu", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Area")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("area");

                    b.Property<string>("Code")
                        .IsRequired()
                        .HasMaxLength(160)
                        .HasColumnType("character varying(160)")
                        .HasColumnName("code");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Icon")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("icon");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("ParentCode")
                        .HasMaxLength(160)
                        .HasColumnType("character varying(160)")
                        .HasColumnName("parent_code");

                    b.Property<string>("Path")
                        .HasMaxLength(1024)
                        .HasColumnType("character varying(1024)")
                        .HasColumnName("path");

                    b.Property<string>("PermissionCode")
                        .HasMaxLength(160)
                        .HasColumnType("character varying(160)")
                        .HasColumnName("permission_code");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("Title")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("title");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_backend_menus");

                    b.HasAlternateKey("Code")
                        .HasName("ak_backend_menus_code");

                    b.HasIndex("Code")
                        .IsUnique()
                        .HasDatabaseName("ix_backend_menus_code");

                    b.HasIndex("PermissionCode")
                        .HasDatabaseName("ix_backend_menus_permission_code");

                    b.HasIndex("Area", "ParentCode", "SortOrder")
                        .HasDatabaseName("ix_backend_menus_area_parent_code_sort_order");

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

            modelBuilder.Entity("Tiku.Domain.Operations.BackendPermission", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Area")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("area");

                    b.Property<string>("Code")
                        .IsRequired()
                        .HasMaxLength(160)
                        .HasColumnType("character varying(160)")
                        .HasColumnName("code");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("description");

                    b.Property<bool>("IsSystem")
                        .HasColumnType("boolean")
                        .HasColumnName("is_system");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<string>("PermissionModuleCode")
                        .IsRequired()
                        .HasMaxLength(120)
                        .HasColumnType("character varying(120)")
                        .HasColumnName("permission_module_code");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_backend_permissions");

                    b.HasAlternateKey("Code")
                        .HasName("ak_backend_permissions_code");

                    b.HasIndex("Code")
                        .IsUnique()
                        .HasDatabaseName("ix_backend_permissions_code");

                    b.HasIndex("PermissionModuleCode")
                        .HasDatabaseName("ix_backend_permissions_permission_module_code");

                    b.HasIndex("Area", "PermissionModuleCode", "SortOrder")
                        .HasDatabaseName("ix_backend_permissions_area_permission_module_code_sort_order");

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

            modelBuilder.Entity("Tiku.Domain.Operations.BackgroundJob", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset?>("CompletedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("completed_at");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("JobType")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("job_type");

                    b.Property<string>("LastError")
                        .HasMaxLength(4000)
                        .HasColumnType("character varying(4000)")
                        .HasColumnName("last_error");

                    b.Property<DateTimeOffset?>("LockExpiresAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("lock_expires_at");

                    b.Property<string>("LockedBy")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("locked_by");

                    b.Property<int>("MaxRetries")
                        .HasColumnType("integer")
                        .HasColumnName("max_retries");

                    b.Property<Guid?>("OutputAssetId")
                        .HasColumnType("uuid")
                        .HasColumnName("output_asset_id");

                    b.Property<JsonElement>("Payload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("payload")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<JsonElement>("Result")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("result")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("RetryCount")
                        .HasColumnType("integer")
                        .HasColumnName("retry_count");

                    b.Property<DateTimeOffset?>("RunAfter")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("run_after");

                    b.Property<DateTimeOffset?>("StartedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("started_at");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_background_jobs");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_background_jobs_tenant_id_id");

                    b.HasIndex("TenantId", "OutputAssetId")
                        .HasDatabaseName("ix_background_jobs_tenant_id_output_asset_id");

                    b.HasIndex("TenantId", "JobType", "Status", "CreatedAt")
                        .HasDatabaseName("ix_background_jobs_tenant_id_job_type_status_created_at");

                    b.HasIndex("TenantId", "Status", "RunAfter", "CreatedAt")
                        .HasDatabaseName("ix_background_jobs_tenant_id_status_run_after_created_at");

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

            modelBuilder.Entity("Tiku.Domain.Operations.Badge", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Category")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("category");

                    b.Property<JsonElement>("ConditionExtra")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("condition_extra")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("ConditionField")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("condition_field");

                    b.Property<string>("ConditionOperator")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("condition_operator");

                    b.Property<decimal?>("ConditionValue")
                        .HasPrecision(18, 4)
                        .HasColumnType("numeric(18,4)")
                        .HasColumnName("condition_value");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<string>("IconUrl")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("icon_url");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<int?>("Level")
                        .HasColumnType("integer")
                        .HasColumnName("level");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("UnlockType")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("unlock_type");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_badges");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_badges_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_badges_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "Category", "IsActive", "SortOrder")
                        .HasDatabaseName("ix_badges_tenant_id_category_is_active_sort_order");

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

            modelBuilder.Entity("Tiku.Domain.Operations.Banner", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("BackgroundColor")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("background_color");

                    b.Property<string>("BorderColor")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("border_color");

                    b.Property<string>("ButtonLink")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("button_link");

                    b.Property<string>("ButtonText")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("button_text");

                    b.Property<string>("Content")
                        .HasColumnType("text")
                        .HasColumnName("content");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("Subtitle")
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("subtitle");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Title")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("title");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_banners");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_banners_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_banners_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RegionId", "IsActive", "SortOrder")
                        .HasDatabaseName("ix_banners_tenant_id_region_id_is_active_sort_order");

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

            modelBuilder.Entity("Tiku.Domain.Operations.Faq", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Answer")
                        .HasColumnType("text")
                        .HasColumnName("answer");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<bool>("IsActive")
                        .HasColumnType("boolean")
                        .HasColumnName("is_active");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("Question")
                        .HasColumnType("text")
                        .HasColumnName("question");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_faqs");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_faqs_tenant_id_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_faqs_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RegionId", "IsActive", "SortOrder")
                        .HasDatabaseName("ix_faqs_tenant_id_region_id_is_active_sort_order");

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

            modelBuilder.Entity("Tiku.Domain.Operations.PlatformBackendRole", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Code")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("code");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("description");

                    b.Property<bool>("IsSystem")
                        .HasColumnType("boolean")
                        .HasColumnName("is_system");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_platform_backend_roles");

                    b.HasIndex("Code")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_backend_roles_code");

                    b.HasIndex("Status", "Code")
                        .HasDatabaseName("ix_platform_backend_roles_status_code");

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

            modelBuilder.Entity("Tiku.Domain.Operations.PlatformBackendRoleMenu", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("MenuCode")
                        .IsRequired()
                        .HasMaxLength(160)
                        .HasColumnType("character varying(160)")
                        .HasColumnName("menu_code");

                    b.Property<Guid>("RoleId")
                        .HasColumnType("uuid")
                        .HasColumnName("role_id");

                    b.HasKey("Id")
                        .HasName("pk_platform_backend_role_menus");

                    b.HasIndex("MenuCode")
                        .HasDatabaseName("ix_platform_backend_role_menus_menu_code");

                    b.HasIndex("RoleId", "MenuCode")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_backend_role_menus_role_id_menu_code");

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

            modelBuilder.Entity("Tiku.Domain.Operations.PlatformBackendRolePermission", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("PermissionCode")
                        .IsRequired()
                        .HasMaxLength(160)
                        .HasColumnType("character varying(160)")
                        .HasColumnName("permission_code");

                    b.Property<Guid>("RoleId")
                        .HasColumnType("uuid")
                        .HasColumnName("role_id");

                    b.HasKey("Id")
                        .HasName("pk_platform_backend_role_permissions");

                    b.HasIndex("PermissionCode")
                        .HasDatabaseName("ix_platform_backend_role_permissions_permission_code");

                    b.HasIndex("RoleId", "PermissionCode")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_backend_role_permissions_role_id_permission_code");

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

            modelBuilder.Entity("Tiku.Domain.Operations.PlatformBackendUserRole", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("RoleId")
                        .HasColumnType("uuid")
                        .HasColumnName("role_id");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_platform_backend_user_roles");

                    b.HasIndex("RoleId")
                        .HasDatabaseName("ix_platform_backend_user_roles_role_id");

                    b.HasIndex("UserId", "RoleId")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_backend_user_roles_user_id_role_id");

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

            modelBuilder.Entity("Tiku.Domain.Operations.TenantBackendRole", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Code")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("code");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("DataScope")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("data_scope")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Description")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("description");

                    b.Property<bool>("IsSystem")
                        .HasColumnType("boolean")
                        .HasColumnName("is_system");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_tenant_backend_roles");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_backend_roles_tenant_id_id");

                    b.HasIndex("TenantId", "Code")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_backend_roles_tenant_id_code");

                    b.HasIndex("TenantId", "Status", "Code")
                        .HasDatabaseName("ix_tenant_backend_roles_tenant_id_status_code");

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

            modelBuilder.Entity("Tiku.Domain.Operations.TenantBackendRoleMenu", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("MenuCode")
                        .IsRequired()
                        .HasMaxLength(160)
                        .HasColumnType("character varying(160)")
                        .HasColumnName("menu_code");

                    b.Property<Guid>("RoleId")
                        .HasColumnType("uuid")
                        .HasColumnName("role_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.HasKey("Id")
                        .HasName("pk_tenant_backend_role_menus");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_backend_role_menus_tenant_id_id");

                    b.HasIndex("MenuCode")
                        .HasDatabaseName("ix_tenant_backend_role_menus_menu_code");

                    b.HasIndex("TenantId", "RoleId", "MenuCode")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_backend_role_menus_tenant_id_role_id_menu_code");

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

            modelBuilder.Entity("Tiku.Domain.Operations.TenantBackendRolePermission", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("PermissionCode")
                        .IsRequired()
                        .HasMaxLength(160)
                        .HasColumnType("character varying(160)")
                        .HasColumnName("permission_code");

                    b.Property<Guid>("RoleId")
                        .HasColumnType("uuid")
                        .HasColumnName("role_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.HasKey("Id")
                        .HasName("pk_tenant_backend_role_permissions");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_backend_role_permissions_tenant_id_id");

                    b.HasIndex("PermissionCode")
                        .HasDatabaseName("ix_tenant_backend_role_permissions_permission_code");

                    b.HasIndex("TenantId", "RoleId", "PermissionCode")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_backend_role_permissions_tenant_id_role_id_permissio~");

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

            modelBuilder.Entity("Tiku.Domain.Operations.TenantBackendUserRole", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("RoleId")
                        .HasColumnType("uuid")
                        .HasColumnName("role_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_tenant_backend_user_roles");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_backend_user_roles_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_tenant_backend_user_roles_user_id");

                    b.HasIndex("TenantId", "RoleId")
                        .HasDatabaseName("ix_tenant_backend_user_roles_tenant_id_role_id");

                    b.HasIndex("TenantId", "UserId", "RoleId")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_backend_user_roles_tenant_id_user_id_role_id");

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

            modelBuilder.Entity("Tiku.Domain.Operations.TenantContentNotification", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("ActionLabel")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("action_label");

                    b.Property<string>("ActionPath")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("action_path");

                    b.Property<Guid?>("AdoptionId")
                        .HasColumnType("uuid")
                        .HasColumnName("adoption_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<string>("DedupeKey")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("dedupe_key");

                    b.Property<string>("Message")
                        .IsRequired()
                        .HasColumnType("text")
                        .HasColumnName("message");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("NotificationType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("notification_type");

                    b.Property<DateTimeOffset?>("ReadAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("read_at");

                    b.Property<Guid?>("ReadBy")
                        .HasColumnType("uuid")
                        .HasColumnName("read_by");

                    b.Property<DateTimeOffset?>("ResolvedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("resolved_at");

                    b.Property<string>("Severity")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("severity");

                    b.Property<Guid?>("SourceQuestionBankId")
                        .HasColumnType("uuid")
                        .HasColumnName("source_question_bank_id");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Title")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("title");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_tenant_content_notifications");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_content_notifications_tenant_id_id");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_tenant_content_notifications_created_by");

                    b.HasIndex("ReadBy")
                        .HasDatabaseName("ix_tenant_content_notifications_read_by");

                    b.HasIndex("TenantId", "SourceQuestionBankId")
                        .HasDatabaseName("ix_tenant_content_notifications_tenant_id_source_question_bank~");

                    b.HasIndex("TenantId", "NotificationType", "DedupeKey")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_content_notifications_tenant_id_notification_type_de~")
                        .HasFilter("dedupe_key is not null");

                    b.HasIndex("TenantId", "Status", "CreatedAt")
                        .HasDatabaseName("ix_tenant_content_notifications_tenant_id_status_created_at");

                    b.HasIndex("TenantId", "AdoptionId", "NotificationType", "Status")
                        .HasDatabaseName("ix_tenant_content_notifications_tenant_id_adoption_id_notifica~");

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

            modelBuilder.Entity("Tiku.Domain.Operations.TenantThemeConfig", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<JsonElement>("ActivePublicAssets")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("active_public_assets")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("ActiveTemplateCode")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("active_template_code");

                    b.Property<JsonElement>("ActiveTheme")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("active_theme")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("DraftPublicAssets")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("draft_public_assets")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("DraftTemplateCode")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("draft_template_code");

                    b.Property<JsonElement>("DraftTheme")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("draft_theme")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid?>("DraftUpdatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("draft_updated_by");

                    b.Property<DateTimeOffset?>("PublishedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("published_at");

                    b.Property<Guid?>("PublishedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("published_by");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_tenant_theme_configs");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_theme_configs_tenant_id_id");

                    b.HasIndex("ActiveTemplateCode")
                        .HasDatabaseName("ix_tenant_theme_configs_active_template_code");

                    b.HasIndex("DraftTemplateCode")
                        .HasDatabaseName("ix_tenant_theme_configs_draft_template_code");

                    b.HasIndex("DraftUpdatedBy")
                        .HasDatabaseName("ix_tenant_theme_configs_draft_updated_by");

                    b.HasIndex("PublishedBy")
                        .HasDatabaseName("ix_tenant_theme_configs_published_by");

                    b.HasIndex("TenantId")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_theme_configs_tenant_id");

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

            modelBuilder.Entity("Tiku.Domain.Operations.TenantThemeTemplate", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Code")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("code");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<string>("PreviewImageUrl")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("preview_image_url");

                    b.Property<JsonElement>("PublicAssets")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("public_assets")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<JsonElement>("Theme")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("theme")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_tenant_theme_templates");

                    b.HasAlternateKey("Code")
                        .HasName("ak_tenant_theme_templates_code");

                    b.HasIndex("Code")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_theme_templates_code");

                    b.HasIndex("Status", "SortOrder", "Code")
                        .HasDatabaseName("ix_tenant_theme_templates_status_sort_order_code");

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

            modelBuilder.Entity("Tiku.Domain.Operations.UserBadge", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid?>("BadgeId")
                        .HasColumnType("uuid")
                        .HasColumnName("badge_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset?>("GrantedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("granted_at");

                    b.Property<Guid?>("GrantedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("granted_by");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("Note")
                        .HasColumnType("text")
                        .HasColumnName("note");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_user_badges");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_user_badges_tenant_id_id");

                    b.HasIndex("GrantedBy")
                        .HasDatabaseName("ix_user_badges_granted_by");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_user_badges_user_id");

                    b.HasIndex("TenantId", "BadgeId")
                        .HasDatabaseName("ix_user_badges_tenant_id_badge_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_user_badges_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "UserId", "BadgeId")
                        .IsUnique()
                        .HasDatabaseName("ix_user_badges_tenant_id_user_id_badge_id");

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

            modelBuilder.Entity("Tiku.Domain.Operations.UserNotification", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("ActionLabel")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("action_label");

                    b.Property<string>("ActionPath")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("action_path");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<string>("DedupeKey")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("dedupe_key");

                    b.Property<string>("Message")
                        .IsRequired()
                        .HasColumnType("text")
                        .HasColumnName("message");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("NotificationType")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("notification_type");

                    b.Property<DateTimeOffset?>("ReadAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("read_at");

                    b.Property<string>("Severity")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("severity");

                    b.Property<Guid?>("SourceId")
                        .HasColumnType("uuid")
                        .HasColumnName("source_id");

                    b.Property<string>("SourceType")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("source_type");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Title")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("title");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_user_notifications");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_user_notifications_tenant_id_id");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_user_notifications_created_by");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_user_notifications_user_id");

                    b.HasIndex("TenantId", "SourceType", "SourceId")
                        .HasDatabaseName("ix_user_notifications_tenant_id_source_type_source_id");

                    b.HasIndex("TenantId", "UserId", "NotificationType", "DedupeKey")
                        .IsUnique()
                        .HasDatabaseName("ix_user_notifications_tenant_id_user_id_notification_type_dedu~")
                        .HasFilter("dedupe_key is not null");

                    b.HasIndex("TenantId", "UserId", "Status", "CreatedAt")
                        .HasDatabaseName("ix_user_notifications_tenant_id_user_id_status_created_at");

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

            modelBuilder.Entity("Tiku.Domain.Platform.PermissionModule", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Area")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("area");

                    b.Property<string>("Code")
                        .IsRequired()
                        .HasMaxLength(120)
                        .HasColumnType("character varying(120)")
                        .HasColumnName("code");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("description");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<string>("RequiredFeatureCode")
                        .HasMaxLength(120)
                        .HasColumnType("character varying(120)")
                        .HasColumnName("required_feature_code");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_permission_modules");

                    b.HasAlternateKey("Code")
                        .HasName("ak_permission_modules_code");

                    b.HasIndex("Code")
                        .IsUnique()
                        .HasDatabaseName("ix_permission_modules_code");

                    b.HasIndex("RequiredFeatureCode")
                        .HasDatabaseName("ix_permission_modules_required_feature_code");

                    b.HasIndex("Area", "SortOrder")
                        .HasDatabaseName("ix_permission_modules_area_sort_order");

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

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformAuditAlert", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset?>("AcknowledgedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("acknowledged_at");

                    b.Property<Guid?>("AcknowledgedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("acknowledged_by");

                    b.Property<string>("Action")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("action");

                    b.Property<Guid>("AuditLogId")
                        .HasColumnType("uuid")
                        .HasColumnName("audit_log_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("Details")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("details")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("FirstSeenAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("first_seen_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset>("LastSeenAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("last_seen_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("ResolutionNote")
                        .HasColumnType("text")
                        .HasColumnName("resolution_note");

                    b.Property<DateTimeOffset?>("ResolvedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("resolved_at");

                    b.Property<Guid?>("ResolvedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("resolved_by");

                    b.Property<Guid>("RuleId")
                        .HasColumnType("uuid")
                        .HasColumnName("rule_id");

                    b.Property<string>("Severity")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("severity");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<string>("Summary")
                        .HasColumnType("text")
                        .HasColumnName("summary");

                    b.Property<string>("TargetId")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("target_id");

                    b.Property<string>("TargetType")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("target_type");

                    b.Property<Guid?>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Title")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("title");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_platform_audit_alerts");

                    b.HasIndex("AcknowledgedBy")
                        .HasDatabaseName("ix_platform_audit_alerts_acknowledged_by");

                    b.HasIndex("AuditLogId")
                        .HasDatabaseName("ix_platform_audit_alerts_audit_log_id");

                    b.HasIndex("ResolvedBy")
                        .HasDatabaseName("ix_platform_audit_alerts_resolved_by");

                    b.HasIndex("RuleId", "AuditLogId")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_audit_alerts_rule_id_audit_log_id");

                    b.HasIndex("Status", "Severity", "CreatedAt")
                        .HasDatabaseName("ix_platform_audit_alerts_status_severity_created_at");

                    b.HasIndex("TenantId", "Status", "CreatedAt")
                        .HasDatabaseName("ix_platform_audit_alerts_tenant_id_status_created_at");

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

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformAuditAlertRule", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.PrimitiveCollection<string[]>("ActionPatterns")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasColumnType("text[]")
                        .HasColumnName("action_patterns")
                        .HasDefaultValueSql("'{}'::text[]");

                    b.Property<string>("Code")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("code");

                    b.Property<JsonElement>("Conditions")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("conditions")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<bool>("Enabled")
                        .HasColumnType("boolean")
                        .HasColumnName("enabled");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<string>("Severity")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("severity");

                    b.PrimitiveCollection<string[]>("TargetTypes")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasColumnType("text[]")
                        .HasColumnName("target_types")
                        .HasDefaultValueSql("'{}'::text[]");

                    b.Property<Guid?>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_platform_audit_alert_rules");

                    b.HasIndex("Code")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_audit_alert_rules_code");

                    b.HasIndex("TenantId")
                        .HasDatabaseName("ix_platform_audit_alert_rules_tenant_id");

                    b.HasIndex("Enabled", "Severity", "Code")
                        .HasDatabaseName("ix_platform_audit_alert_rules_enabled_severity_code");

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

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingDunningNotificationChannel", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("ChannelCode")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("channel_code");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<bool>("Enabled")
                        .HasColumnType("boolean")
                        .HasColumnName("enabled");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("MinReminderLevel")
                        .HasColumnType("integer")
                        .HasColumnName("min_reminder_level");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("provider");

                    b.PrimitiveCollection<string[]>("ReminderChannels")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasColumnType("text[]")
                        .HasColumnName("reminder_channels")
                        .HasDefaultValueSql("array['internal']::text[]");

                    b.PrimitiveCollection<string[]>("ReminderTypes")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasColumnType("text[]")
                        .HasColumnName("reminder_types")
                        .HasDefaultValueSql("array['overdue', 'final_notice']::text[]");

                    b.Property<string>("SecretRef")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("secret_ref");

                    b.PrimitiveCollection<Guid[]>("TenantIds")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid[]")
                        .HasColumnName("tenant_ids")
                        .HasDefaultValueSql("'{}'::uuid[]");

                    b.Property<int>("TimeoutSeconds")
                        .HasColumnType("integer")
                        .HasColumnName("timeout_seconds");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("WebhookUrl")
                        .IsRequired()
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("webhook_url");

                    b.HasKey("Id")
                        .HasName("pk_platform_billing_dunning_notification_channels");

                    b.HasIndex("ChannelCode")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_billing_dunning_notification_channels_channel_code");

                    b.HasIndex("Enabled", "MinReminderLevel", "ChannelCode")
                        .HasDatabaseName("ix_platform_billing_dunning_notification_channels_enabled_min_~");

                    b.ToTable("platform_billing_dunning_notification_channels", null, t =>
                        {
                            t.HasCheckConstraint("ck_platform_billing_dunning_channels_level", "min_reminder_level between 1 and 20");

                            t.HasCheckConstraint("ck_platform_billing_dunning_channels_timeout", "timeout_seconds between 1 and 60");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingDunningNotificationEvent", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("Attempts")
                        .HasColumnType("integer")
                        .HasColumnName("attempts");

                    b.Property<Guid>("ChannelId")
                        .HasColumnType("uuid")
                        .HasColumnName("channel_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("InvoiceId")
                        .HasColumnType("uuid")
                        .HasColumnName("invoice_id");

                    b.Property<DateTimeOffset?>("LastAttemptAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("last_attempt_at");

                    b.Property<string>("LastError")
                        .HasColumnType("text")
                        .HasColumnName("last_error");

                    b.Property<int?>("LastHttpCode")
                        .HasColumnType("integer")
                        .HasColumnName("last_http_code");

                    b.Property<string>("LastResponseSummary")
                        .HasColumnType("text")
                        .HasColumnName("last_response_summary");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset?>("NextAttemptAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("next_attempt_at");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("provider");

                    b.Property<Guid>("ReminderId")
                        .HasColumnType("uuid")
                        .HasColumnName("reminder_id");

                    b.Property<JsonElement>("RequestPayload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("request_payload")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("ScheduledAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("scheduled_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset?>("SentAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("sent_at");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_platform_billing_dunning_notification_events");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_platform_billing_dunning_notification_events_tenant_id_id");

                    b.HasIndex("ChannelId")
                        .HasDatabaseName("ix_platform_billing_dunning_notification_events_channel_id");

                    b.HasIndex("TenantId", "InvoiceId")
                        .HasDatabaseName("ix_platform_billing_dunning_notification_events_tenant_id_invo~");

                    b.HasIndex("TenantId", "ReminderId")
                        .HasDatabaseName("ix_platform_billing_dunning_notification_events_tenant_id_remi~");

                    b.HasIndex("InvoiceId", "Status", "CreatedAt")
                        .HasDatabaseName("ix_platform_billing_dunning_notification_events_invoice_id_sta~");

                    b.HasIndex("ReminderId", "Status", "CreatedAt")
                        .HasDatabaseName("ix_platform_billing_dunning_notification_events_reminder_id_st~");

                    b.HasIndex("TenantId", "ChannelId", "ReminderId")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_billing_dunning_notification_events_tenant_id_chan~");

                    b.HasIndex("TenantId", "Status", "CreatedAt")
                        .HasDatabaseName("ix_platform_billing_dunning_notification_events_tenant_id_stat~");

                    b.HasIndex("Status", "NextAttemptAt", "ScheduledAt", "CreatedAt")
                        .HasDatabaseName("ix_platform_billing_dunning_notification_events_status_next_at~");

                    b.ToTable("platform_billing_dunning_notification_events", null, t =>
                        {
                            t.HasCheckConstraint("ck_platform_billing_dunning_events_attempts", "attempts >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingInvoice", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<JsonElement>("BillingProfileSnapshot")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("billing_profile_snapshot")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Currency")
                        .IsRequired()
                        .HasMaxLength(10)
                        .HasColumnType("character varying(10)")
                        .HasColumnName("currency");

                    b.Property<DateOnly?>("DueDate")
                        .HasColumnType("date")
                        .HasColumnName("due_date");

                    b.Property<string>("InvoiceNo")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("invoice_no");

                    b.Property<DateTimeOffset?>("IssuedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("issued_at");

                    b.Property<Guid?>("OrderId")
                        .HasColumnType("uuid")
                        .HasColumnName("order_id");

                    b.Property<DateTimeOffset?>("PaidAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("paid_at");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<int>("TotalAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("total_amount_cents");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_platform_billing_invoices");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_platform_billing_invoices_tenant_id_id");

                    b.HasIndex("TenantId", "InvoiceNo")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_billing_invoices_tenant_id_invoice_no");

                    b.HasIndex("TenantId", "OrderId")
                        .HasDatabaseName("ix_platform_billing_invoices_tenant_id_order_id");

                    b.HasIndex("TenantId", "Status", "DueDate")
                        .HasDatabaseName("ix_platform_billing_invoices_tenant_id_status_due_date");

                    b.ToTable("platform_billing_invoices", null, t =>
                        {
                            t.HasCheckConstraint("ck_platform_billing_invoices_amount", "total_amount_cents >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingInvoiceReminder", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset?>("AcknowledgedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("acknowledged_at");

                    b.Property<int>("BalanceCentsSnapshot")
                        .HasColumnType("integer")
                        .HasColumnName("balance_cents_snapshot");

                    b.Property<string>("Channel")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("channel");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<DateOnly?>("DueDate")
                        .HasColumnType("date")
                        .HasColumnName("due_date");

                    b.Property<Guid>("InvoiceId")
                        .HasColumnType("uuid")
                        .HasColumnName("invoice_id");

                    b.Property<string>("Message")
                        .HasColumnType("text")
                        .HasColumnName("message");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateOnly>("ReminderDate")
                        .HasColumnType("date")
                        .HasColumnName("reminder_date");

                    b.Property<int>("ReminderLevel")
                        .HasColumnType("integer")
                        .HasColumnName("reminder_level");

                    b.Property<string>("ReminderType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("reminder_type");

                    b.Property<DateTimeOffset?>("SentAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("sent_at");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_platform_billing_invoice_reminders");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_platform_billing_invoice_reminders_tenant_id_id");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_platform_billing_invoice_reminders_created_by");

                    b.HasIndex("InvoiceId", "ReminderDate")
                        .HasDatabaseName("ix_platform_billing_invoice_reminders_invoice_id_reminder_date");

                    b.HasIndex("TenantId", "Status", "ReminderDate")
                        .HasDatabaseName("ix_platform_billing_invoice_reminders_tenant_id_status_reminde~");

                    b.HasIndex("TenantId", "InvoiceId", "ReminderType", "Channel", "ReminderDate")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_billing_invoice_reminders_tenant_id_invoice_id_rem~");

                    b.ToTable("platform_billing_invoice_reminders", null, t =>
                        {
                            t.HasCheckConstraint("ck_platform_billing_invoice_reminders_balance", "balance_cents_snapshot >= 0");

                            t.HasCheckConstraint("ck_platform_billing_invoice_reminders_level", "reminder_level between 1 and 20");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingOrder", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset?>("CancelledAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("cancelled_at");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Currency")
                        .IsRequired()
                        .HasMaxLength(10)
                        .HasColumnType("character varying(10)")
                        .HasColumnName("currency");

                    b.Property<int>("DiscountAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("discount_amount_cents");

                    b.Property<DateTimeOffset>("ExpiresAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("expires_at");

                    b.Property<string>("IdempotencyKey")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("idempotency_key");

                    b.Property<string>("OrderNo")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("order_no");

                    b.Property<int>("OriginalAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("original_amount_cents");

                    b.Property<DateTimeOffset?>("PaidAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("paid_at");

                    b.Property<string>("Purpose")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("purpose");

                    b.Property<Guid>("QuoteId")
                        .HasColumnType("uuid")
                        .HasColumnName("quote_id");

                    b.Property<JsonElement>("Snapshot")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("snapshot")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<int>("TotalAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("total_amount_cents");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_platform_billing_orders");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_platform_billing_orders_tenant_id_id");

                    b.HasIndex("TenantId", "IdempotencyKey")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_billing_orders_tenant_id_idempotency_key");

                    b.HasIndex("TenantId", "OrderNo")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_billing_orders_tenant_id_order_no");

                    b.HasIndex("TenantId", "QuoteId")
                        .HasDatabaseName("ix_platform_billing_orders_tenant_id_quote_id");

                    b.HasIndex("TenantId", "Status", "CreatedAt")
                        .HasDatabaseName("ix_platform_billing_orders_tenant_id_status_created_at");

                    b.ToTable("platform_billing_orders", null, t =>
                        {
                            t.HasCheckConstraint("ck_platform_billing_orders_amounts", "original_amount_cents >= 0 and discount_amount_cents >= 0 and total_amount_cents >= 0 and total_amount_cents = original_amount_cents - discount_amount_cents");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingOrderItem", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("AmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("amount_cents");

                    b.Property<string>("ItemType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("item_type");

                    b.Property<Guid>("OfferingVersionId")
                        .HasColumnType("uuid")
                        .HasColumnName("offering_version_id");

                    b.Property<Guid>("OrderId")
                        .HasColumnType("uuid")
                        .HasColumnName("order_id");

                    b.Property<int>("Quantity")
                        .HasColumnType("integer")
                        .HasColumnName("quantity");

                    b.Property<JsonElement>("Snapshot")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("snapshot")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<int>("UnitAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("unit_amount_cents");

                    b.HasKey("Id")
                        .HasName("pk_platform_billing_order_items");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_platform_billing_order_items_tenant_id_id");

                    b.HasIndex("OfferingVersionId")
                        .HasDatabaseName("ix_platform_billing_order_items_offering_version_id");

                    b.HasIndex("TenantId", "OrderId", "OfferingVersionId")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_billing_order_items_tenant_id_order_id_offering_ve~");

                    b.ToTable("platform_billing_order_items", null, t =>
                        {
                            t.HasCheckConstraint("ck_platform_billing_order_items_amounts", "quantity > 0 and unit_amount_cents >= 0 and amount_cents >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingPayment", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("AmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("amount_cents");

                    b.Property<JsonElement>("ClientPayload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("client_payload")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("IdempotencyKey")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("idempotency_key");

                    b.Property<string>("Method")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("method");

                    b.Property<Guid>("OrderId")
                        .HasColumnType("uuid")
                        .HasColumnName("order_id");

                    b.Property<DateTimeOffset?>("PaidAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("paid_at");

                    b.Property<string>("PaymentNo")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("payment_no");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("provider");

                    b.Property<string>("ProviderTradeNo")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("provider_trade_no");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_platform_billing_payments");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_platform_billing_payments_tenant_id_id");

                    b.HasIndex("TenantId", "IdempotencyKey")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_billing_payments_tenant_id_idempotency_key");

                    b.HasIndex("TenantId", "PaymentNo")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_billing_payments_tenant_id_payment_no");

                    b.HasIndex("TenantId", "OrderId", "Status")
                        .HasDatabaseName("ix_platform_billing_payments_tenant_id_order_id_status");

                    b.ToTable("platform_billing_payments", null, t =>
                        {
                            t.HasCheckConstraint("ck_platform_billing_payments_amount", "amount_cents >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingPaymentEvent", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("EventType")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("event_type");

                    b.Property<JsonElement>("Payload")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("payload")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid>("PaymentId")
                        .HasColumnType("uuid")
                        .HasColumnName("payment_id");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("provider");

                    b.Property<string>("ProviderEventId")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("provider_event_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.HasKey("Id")
                        .HasName("pk_platform_billing_payment_events");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_platform_billing_payment_events_tenant_id_id");

                    b.HasIndex("TenantId", "PaymentId", "CreatedAt")
                        .HasDatabaseName("ix_platform_billing_payment_events_tenant_id_payment_id_create~");

                    b.HasIndex("TenantId", "Provider", "ProviderEventId")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_billing_payment_events_tenant_id_provider_provider~");

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

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingQuote", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Currency")
                        .IsRequired()
                        .HasMaxLength(10)
                        .HasColumnType("character varying(10)")
                        .HasColumnName("currency");

                    b.Property<int>("DiscountAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("discount_amount_cents");

                    b.Property<DateTimeOffset>("ExpiresAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("expires_at");

                    b.Property<JsonElement>("FeatureSnapshot")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("feature_snapshot")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<string>("IdempotencyKey")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("idempotency_key");

                    b.Property<JsonElement>("LimitSnapshot")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("limit_snapshot")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("OriginalAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("original_amount_cents");

                    b.Property<string>("Purpose")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("purpose");

                    b.Property<string>("QuoteNo")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("quote_no");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<int>("TotalAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("total_amount_cents");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_platform_billing_quotes");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_platform_billing_quotes_tenant_id_id");

                    b.HasIndex("TenantId", "IdempotencyKey")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_billing_quotes_tenant_id_idempotency_key");

                    b.HasIndex("TenantId", "QuoteNo")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_billing_quotes_tenant_id_quote_no");

                    b.HasIndex("TenantId", "Status", "ExpiresAt")
                        .HasDatabaseName("ix_platform_billing_quotes_tenant_id_status_expires_at");

                    b.ToTable("platform_billing_quotes", null, t =>
                        {
                            t.HasCheckConstraint("ck_platform_billing_quotes_amounts", "original_amount_cents >= 0 and discount_amount_cents >= 0 and total_amount_cents >= 0 and total_amount_cents = original_amount_cents - discount_amount_cents");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingQuoteItem", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("AmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("amount_cents");

                    b.Property<string>("ItemType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("item_type");

                    b.Property<Guid>("OfferingVersionId")
                        .HasColumnType("uuid")
                        .HasColumnName("offering_version_id");

                    b.Property<int>("Quantity")
                        .HasColumnType("integer")
                        .HasColumnName("quantity");

                    b.Property<Guid>("QuoteId")
                        .HasColumnType("uuid")
                        .HasColumnName("quote_id");

                    b.Property<JsonElement>("Snapshot")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("snapshot")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<int>("UnitAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("unit_amount_cents");

                    b.HasKey("Id")
                        .HasName("pk_platform_billing_quote_items");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_platform_billing_quote_items_tenant_id_id");

                    b.HasIndex("OfferingVersionId")
                        .HasDatabaseName("ix_platform_billing_quote_items_offering_version_id");

                    b.HasIndex("TenantId", "QuoteId", "OfferingVersionId")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_billing_quote_items_tenant_id_quote_id_offering_ve~");

                    b.ToTable("platform_billing_quote_items", null, t =>
                        {
                            t.HasCheckConstraint("ck_platform_billing_quote_items_amounts", "quantity > 0 and unit_amount_cents >= 0 and amount_cents >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingRefund", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("AmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("amount_cents");

                    b.Property<DateTimeOffset?>("CompletedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("completed_at");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("OrderId")
                        .HasColumnType("uuid")
                        .HasColumnName("order_id");

                    b.Property<Guid?>("PaymentId")
                        .HasColumnType("uuid")
                        .HasColumnName("payment_id");

                    b.Property<string>("ProviderRefundNo")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("provider_refund_no");

                    b.Property<string>("Reason")
                        .IsRequired()
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("reason");

                    b.Property<string>("RefundNo")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("refund_no");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_platform_billing_refunds");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_platform_billing_refunds_tenant_id_id");

                    b.HasIndex("TenantId", "PaymentId")
                        .HasDatabaseName("ix_platform_billing_refunds_tenant_id_payment_id");

                    b.HasIndex("TenantId", "RefundNo")
                        .IsUnique()
                        .HasDatabaseName("ix_platform_billing_refunds_tenant_id_refund_no");

                    b.HasIndex("TenantId", "OrderId", "Status")
                        .HasDatabaseName("ix_platform_billing_refunds_tenant_id_order_id_status");

                    b.ToTable("platform_billing_refunds", null, t =>
                        {
                            t.HasCheckConstraint("ck_platform_billing_refunds_amount", "amount_cents > 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.SaasFeature", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Category")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("category");

                    b.Property<string>("Code")
                        .IsRequired()
                        .HasMaxLength(120)
                        .HasColumnType("character varying(120)")
                        .HasColumnName("code");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Currency")
                        .IsRequired()
                        .HasMaxLength(10)
                        .HasColumnType("character varying(10)")
                        .HasColumnName("currency");

                    b.Property<string>("Description")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("description");

                    b.Property<bool>("IsCore")
                        .HasColumnType("boolean")
                        .HasColumnName("is_core");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<int>("ReferencePriceCents")
                        .HasColumnType("integer")
                        .HasColumnName("reference_price_cents");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_saas_features");

                    b.HasAlternateKey("Code")
                        .HasName("ak_saas_features_code");

                    b.HasIndex("Code")
                        .IsUnique()
                        .HasDatabaseName("ix_saas_features_code");

                    b.HasIndex("Status", "Category", "SortOrder")
                        .HasDatabaseName("ix_saas_features_status_category_sort_order");

                    b.ToTable("saas_features", null, t =>
                        {
                            t.HasCheckConstraint("ck_saas_features_reference_price", "reference_price_cents >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.SaasFeatureLimitDefinition", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("FeatureCode")
                        .IsRequired()
                        .HasMaxLength(120)
                        .HasColumnType("character varying(120)")
                        .HasColumnName("feature_code");

                    b.Property<bool>("IsHardLimit")
                        .HasColumnType("boolean")
                        .HasColumnName("is_hard_limit");

                    b.Property<string>("Kind")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("kind");

                    b.Property<string>("MetricCode")
                        .IsRequired()
                        .HasMaxLength(120)
                        .HasColumnType("character varying(120)")
                        .HasColumnName("metric_code");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<string>("Unit")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("unit");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int>("WarningPercent")
                        .HasColumnType("integer")
                        .HasColumnName("warning_percent");

                    b.HasKey("Id")
                        .HasName("pk_saas_feature_limit_definitions");

                    b.HasAlternateKey("MetricCode")
                        .HasName("ak_saas_feature_limit_definitions_metric_code");

                    b.HasIndex("MetricCode")
                        .IsUnique()
                        .HasDatabaseName("ix_saas_feature_limit_definitions_metric_code");

                    b.HasIndex("FeatureCode", "Kind")
                        .HasDatabaseName("ix_saas_feature_limit_definitions_feature_code_kind");

                    b.ToTable("saas_feature_limit_definitions", null, t =>
                        {
                            t.HasCheckConstraint("ck_saas_feature_limit_warning", "warning_percent between 1 and 100");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.SaasOffering", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Code")
                        .IsRequired()
                        .HasMaxLength(120)
                        .HasColumnType("character varying(120)")
                        .HasColumnName("code");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Description")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("description");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<string>("Type")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("type");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_saas_offerings");

                    b.HasIndex("Code")
                        .IsUnique()
                        .HasDatabaseName("ix_saas_offerings_code");

                    b.HasIndex("Type", "Status", "SortOrder")
                        .HasDatabaseName("ix_saas_offerings_type_status_sort_order");

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

            modelBuilder.Entity("Tiku.Domain.Platform.SaasOfferingVersion", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("AmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("amount_cents");

                    b.Property<string>("BillingCycle")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("billing_cycle");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("Currency")
                        .IsRequired()
                        .HasMaxLength(10)
                        .HasColumnType("character varying(10)")
                        .HasColumnName("currency");

                    b.Property<DateTimeOffset?>("EffectiveAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("effective_at");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid>("OfferingId")
                        .HasColumnType("uuid")
                        .HasColumnName("offering_id");

                    b.Property<int>("OriginalAmountCents")
                        .HasColumnType("integer")
                        .HasColumnName("original_amount_cents");

                    b.Property<DateTimeOffset?>("PublishedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("published_at");

                    b.Property<DateTimeOffset?>("RetiredAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("retired_at");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<int>("Version")
                        .HasColumnType("integer")
                        .HasColumnName("version");

                    b.HasKey("Id")
                        .HasName("pk_saas_offering_versions");

                    b.HasIndex("OfferingId", "Version")
                        .IsUnique()
                        .HasDatabaseName("ix_saas_offering_versions_offering_id_version");

                    b.HasIndex("OfferingId", "Status", "EffectiveAt")
                        .HasDatabaseName("ix_saas_offering_versions_offering_id_status_effective_at");

                    b.ToTable("saas_offering_versions", null, t =>
                        {
                            t.HasCheckConstraint("ck_saas_offering_versions_amount", "original_amount_cents >= 0 and amount_cents >= 0 and amount_cents <= original_amount_cents");

                            t.HasCheckConstraint("ck_saas_offering_versions_version", "version > 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.SaasOfferingVersionFeature", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("FeatureCode")
                        .IsRequired()
                        .HasMaxLength(120)
                        .HasColumnType("character varying(120)")
                        .HasColumnName("feature_code");

                    b.Property<Guid>("OfferingVersionId")
                        .HasColumnType("uuid")
                        .HasColumnName("offering_version_id");

                    b.HasKey("Id")
                        .HasName("pk_saas_offering_version_features");

                    b.HasIndex("FeatureCode")
                        .HasDatabaseName("ix_saas_offering_version_features_feature_code");

                    b.HasIndex("OfferingVersionId", "FeatureCode")
                        .IsUnique()
                        .HasDatabaseName("ix_saas_offering_version_features_offering_version_id_feature_~");

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

            modelBuilder.Entity("Tiku.Domain.Platform.SaasOfferingVersionLimit", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<long>("LimitValue")
                        .HasColumnType("bigint")
                        .HasColumnName("limit_value");

                    b.Property<string>("MetricCode")
                        .IsRequired()
                        .HasMaxLength(120)
                        .HasColumnType("character varying(120)")
                        .HasColumnName("metric_code");

                    b.Property<Guid>("OfferingVersionId")
                        .HasColumnType("uuid")
                        .HasColumnName("offering_version_id");

                    b.HasKey("Id")
                        .HasName("pk_saas_offering_version_limits");

                    b.HasIndex("MetricCode")
                        .HasDatabaseName("ix_saas_offering_version_limits_metric_code");

                    b.HasIndex("OfferingVersionId", "MetricCode")
                        .IsUnique()
                        .HasDatabaseName("ix_saas_offering_version_limits_offering_version_id_metric_code");

                    b.ToTable("saas_offering_version_limits", null, t =>
                        {
                            t.HasCheckConstraint("ck_saas_offering_version_limits_value", "limit_value >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.TenantBillingProfile", b =>
                {
                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("BankAccountMasked")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("bank_account_masked");

                    b.Property<string>("BankName")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("bank_name");

                    b.Property<string>("BillingAddress")
                        .HasColumnType("text")
                        .HasColumnName("billing_address");

                    b.Property<string>("BillingName")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("billing_name");

                    b.Property<string>("ContactEmail")
                        .HasMaxLength(300)
                        .HasColumnType("citext")
                        .HasColumnName("contact_email");

                    b.Property<string>("ContactName")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("contact_name");

                    b.Property<string>("ContactPhone")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("contact_phone");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("InvoiceTitle")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("invoice_title");

                    b.Property<string>("InvoiceType")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("invoice_type");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("TaxId")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("tax_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("TenantId")
                        .HasName("pk_tenant_billing_profiles");

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

            modelBuilder.Entity("Tiku.Domain.Platform.TenantFeatureOverride", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset?>("ExpiresAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("expires_at");

                    b.Property<string>("FeatureCode")
                        .IsRequired()
                        .HasMaxLength(120)
                        .HasColumnType("character varying(120)")
                        .HasColumnName("feature_code");

                    b.Property<string>("Mode")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("mode");

                    b.Property<string>("Reason")
                        .IsRequired()
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("reason");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_tenant_feature_overrides");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_feature_overrides_tenant_id_id");

                    b.HasIndex("FeatureCode")
                        .HasDatabaseName("ix_tenant_feature_overrides_feature_code");

                    b.HasIndex("TenantId", "FeatureCode")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_feature_overrides_tenant_id_feature_code");

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

            modelBuilder.Entity("Tiku.Domain.Platform.TenantFeatureUsage", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<long>("LimitValueSnapshot")
                        .HasColumnType("bigint")
                        .HasColumnName("limit_value_snapshot");

                    b.Property<string>("MetricCode")
                        .IsRequired()
                        .HasMaxLength(120)
                        .HasColumnType("character varying(120)")
                        .HasColumnName("metric_code");

                    b.Property<DateTimeOffset>("PeriodEnd")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("period_end");

                    b.Property<DateTimeOffset>("PeriodStart")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("period_start");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<long>("UsedValue")
                        .HasColumnType("bigint")
                        .HasColumnName("used_value");

                    b.Property<long>("Version")
                        .IsConcurrencyToken()
                        .HasColumnType("bigint")
                        .HasColumnName("version");

                    b.Property<bool>("WarningIssued")
                        .HasColumnType("boolean")
                        .HasColumnName("warning_issued");

                    b.HasKey("Id")
                        .HasName("pk_tenant_feature_usage");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_feature_usage_tenant_id_id");

                    b.HasIndex("MetricCode")
                        .HasDatabaseName("ix_tenant_feature_usage_metric_code");

                    b.HasIndex("TenantId", "MetricCode", "PeriodStart", "PeriodEnd")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_feature_usage_tenant_id_metric_code_period_start_per~");

                    b.ToTable("tenant_feature_usage", null, t =>
                        {
                            t.HasCheckConstraint("ck_tenant_feature_usage_period", "period_end > period_start");

                            t.HasCheckConstraint("ck_tenant_feature_usage_values", "used_value >= 0 and limit_value_snapshot >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.TenantSaasSubscription", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid>("BaseOfferingVersionId")
                        .HasColumnType("uuid")
                        .HasColumnName("base_offering_version_id");

                    b.Property<bool>("CancelAtPeriodEnd")
                        .HasColumnType("boolean")
                        .HasColumnName("cancel_at_period_end");

                    b.Property<DateTimeOffset?>("CancelledAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("cancelled_at");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset>("CurrentPeriodEnd")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("current_period_end");

                    b.Property<DateTimeOffset>("CurrentPeriodStart")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("current_period_start");

                    b.Property<long>("LifecycleVersion")
                        .IsConcurrencyToken()
                        .HasColumnType("bigint")
                        .HasColumnName("lifecycle_version");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid?>("ScheduledBaseOfferingVersionId")
                        .HasColumnType("uuid")
                        .HasColumnName("scheduled_base_offering_version_id");

                    b.Property<DateTimeOffset>("StartsAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("starts_at");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_tenant_saas_subscriptions");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_saas_subscriptions_tenant_id_id");

                    b.HasIndex("BaseOfferingVersionId")
                        .HasDatabaseName("ix_tenant_saas_subscriptions_base_offering_version_id");

                    b.HasIndex("ScheduledBaseOfferingVersionId")
                        .HasDatabaseName("ix_tenant_saas_subscriptions_scheduled_base_offering_version_id");

                    b.HasIndex("TenantId")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_saas_subscriptions_tenant_id")
                        .HasFilter("status in ('trial', 'active', 'past_due', 'suspended')");

                    b.HasIndex("TenantId", "Status", "CurrentPeriodEnd")
                        .HasDatabaseName("ix_tenant_saas_subscriptions_tenant_id_status_current_period_e~");

                    b.ToTable("tenant_saas_subscriptions", null, t =>
                        {
                            t.HasCheckConstraint("ck_tenant_saas_subscriptions_period", "current_period_end > current_period_start and current_period_start >= starts_at");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Platform.TenantSaasSubscriptionItem", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset>("EndsAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("ends_at");

                    b.Property<string>("ItemType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("item_type");

                    b.Property<Guid>("OfferingVersionId")
                        .HasColumnType("uuid")
                        .HasColumnName("offering_version_id");

                    b.Property<Guid?>("SourceOrderItemId")
                        .HasColumnType("uuid")
                        .HasColumnName("source_order_item_id");

                    b.Property<DateTimeOffset>("StartsAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("starts_at");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("SubscriptionId")
                        .HasColumnType("uuid")
                        .HasColumnName("subscription_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_tenant_saas_subscription_items");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_saas_subscription_items_tenant_id_id");

                    b.HasIndex("OfferingVersionId")
                        .HasDatabaseName("ix_tenant_saas_subscription_items_offering_version_id");

                    b.HasIndex("TenantId", "SourceOrderItemId")
                        .HasDatabaseName("ix_tenant_saas_subscription_items_tenant_id_source_order_item_~");

                    b.HasIndex("TenantId", "SubscriptionId", "ItemType")
                        .IsUnique()
                        .HasDatabaseName("ux_tenant_saas_subscription_items_current_base")
                        .HasFilter("item_type = 'base_plan' and status = 'active'");

                    b.HasIndex("TenantId", "SubscriptionId", "Status")
                        .IsUnique()
                        .HasDatabaseName("ux_tenant_saas_subscription_items_scheduled_base")
                        .HasFilter("item_type = 'base_plan' and status = 'scheduled'");

                    b.HasIndex("TenantId", "SubscriptionId", "OfferingVersionId", "Status")
                        .HasDatabaseName("ix_tenant_saas_subscription_items_tenant_id_subscription_id_of~");

                    b.ToTable("tenant_saas_subscription_items", null, t =>
                        {
                            t.HasCheckConstraint("ck_tenant_saas_subscription_items_period", "ends_at > starts_at");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.QuestionBanks.Question", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid?>("CategoryId")
                        .HasColumnType("uuid")
                        .HasColumnName("category_id");

                    b.Property<Guid?>("ContentNodeId")
                        .HasColumnType("uuid")
                        .HasColumnName("content_node_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CurrentVersionId")
                        .HasColumnType("uuid")
                        .HasColumnName("current_version_id");

                    b.Property<int?>("Difficulty")
                        .HasColumnType("integer")
                        .HasColumnName("difficulty");

                    b.Property<Guid?>("EntryId")
                        .HasColumnType("uuid")
                        .HasColumnName("entry_id");

                    b.Property<JsonElement>("ExamMarkers")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("exam_markers")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<bool>("HasVideoExplanation")
                        .HasColumnType("boolean")
                        .HasColumnName("has_video_explanation");

                    b.Property<string>("LegacyCategoryId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_category_id");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("LegacyNodeId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_node_id");

                    b.Property<string>("LegacySubjectId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_subject_id");

                    b.Property<string>("MediaUrl")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("media_url");

                    b.Property<Guid?>("NodeId")
                        .HasColumnType("uuid")
                        .HasColumnName("node_id");

                    b.Property<Guid?>("PrimaryCollectionId")
                        .HasColumnType("uuid")
                        .HasColumnName("primary_collection_id");

                    b.Property<Guid?>("QuestionBankId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_bank_id");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid?>("SubjectId")
                        .HasColumnType("uuid")
                        .HasColumnName("subject_id");

                    b.Property<JsonElement>("Tags")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("tags")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Type")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("type");

                    b.Property<string>("TypeLabel")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("type_label");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_questions");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_questions_tenant_id_id");

                    b.HasIndex("TenantId", "CategoryId")
                        .HasDatabaseName("ix_questions_tenant_id_category_id");

                    b.HasIndex("TenantId", "ContentNodeId")
                        .HasDatabaseName("ix_questions_tenant_id_content_node_id");

                    b.HasIndex("TenantId", "EntryId")
                        .HasDatabaseName("ix_questions_tenant_id_entry_id");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_questions_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "NodeId")
                        .HasDatabaseName("ix_questions_tenant_id_node_id");

                    b.HasIndex("TenantId", "PrimaryCollectionId")
                        .HasDatabaseName("ix_questions_tenant_id_primary_collection_id");

                    b.HasIndex("TenantId", "QuestionBankId")
                        .HasDatabaseName("ix_questions_tenant_id_question_bank_id");

                    b.HasIndex("TenantId", "SubjectId")
                        .HasDatabaseName("ix_questions_tenant_id_subject_id");

                    b.HasIndex("TenantId", "Id", "CurrentVersionId")
                        .HasDatabaseName("ix_questions_tenant_id_id_current_version_id");

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

            modelBuilder.Entity("Tiku.Domain.QuestionBanks.QuestionBank", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("name");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_question_banks");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_question_banks_tenant_id_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_question_banks_tenant_id_region_id");

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

            modelBuilder.Entity("Tiku.Domain.QuestionBanks.QuestionVersion", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("AnswerText")
                        .HasColumnType("text")
                        .HasColumnName("answer_text");

                    b.Property<string>("CodeLang")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("code_lang");

                    b.Property<string>("CodeTemplate")
                        .HasColumnType("text")
                        .HasColumnName("code_template");

                    b.Property<string>("Content")
                        .HasColumnType("text")
                        .HasColumnName("content");

                    b.Property<int?>("CorrectOptionIndex")
                        .HasColumnType("integer")
                        .HasColumnName("correct_option_index");

                    b.Property<JsonElement>("CorrectOptionIndices")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("correct_option_indices")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<string>("Explanation")
                        .HasColumnType("text")
                        .HasColumnName("explanation");

                    b.Property<JsonElement>("Options")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("options")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<Guid>("QuestionId")
                        .HasColumnType("uuid")
                        .HasColumnName("question_id");

                    b.Property<string>("SourceHash")
                        .HasMaxLength(128)
                        .HasColumnType("character varying(128)")
                        .HasColumnName("source_hash");

                    b.Property<JsonElement>("SubQuestions")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("sub_questions")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<int>("VersionNo")
                        .HasColumnType("integer")
                        .HasColumnName("version_no");

                    b.HasKey("Id")
                        .HasName("pk_question_versions");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_question_versions_tenant_id_id");

                    b.HasAlternateKey("TenantId", "QuestionId", "Id")
                        .HasName("ak_question_versions_tenant_id_question_id_id");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_question_versions_created_by");

                    b.HasIndex("TenantId", "QuestionId", "VersionNo")
                        .IsUnique()
                        .HasDatabaseName("ix_question_versions_tenant_id_question_id_version_no");

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

            modelBuilder.Entity("Tiku.Domain.Tenancy.AuthChallenge", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset?>("ConsumedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("consumed_at");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset>("ExpiresAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("expires_at");

                    b.Property<string>("IpAddress")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("ip_address");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("provider");

                    b.Property<string>("Purpose")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("purpose");

                    b.Property<string>("Realm")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("realm");

                    b.Property<string>("SecurityStamp")
                        .IsRequired()
                        .HasMaxLength(128)
                        .HasColumnType("character varying(128)")
                        .HasColumnName("security_stamp");

                    b.Property<Guid?>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("TokenHash")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("token_hash");

                    b.Property<string>("UserAgent")
                        .HasMaxLength(1024)
                        .HasColumnType("character varying(1024)")
                        .HasColumnName("user_agent");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_auth_challenges");

                    b.HasIndex("TenantId")
                        .HasDatabaseName("ix_auth_challenges_tenant_id");

                    b.HasIndex("TokenHash")
                        .IsUnique()
                        .HasDatabaseName("ix_auth_challenges_token_hash");

                    b.HasIndex("UserId", "Purpose", "ExpiresAt")
                        .HasDatabaseName("ix_auth_challenges_user_id_purpose_expires_at");

                    b.ToTable("auth_challenges", null, t =>
                        {
                            t.HasCheckConstraint("ck_auth_challenges_realm_tenant", "(realm = 'tenant' and tenant_id is not null) or (realm = 'platform' and tenant_id is null)");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.AuthLoginEvent", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("FailureCode")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("failure_code");

                    b.Property<string>("Identifier")
                        .HasMaxLength(320)
                        .HasColumnType("character varying(320)")
                        .HasColumnName("identifier");

                    b.Property<string>("IpAddress")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("ip_address");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("provider");

                    b.Property<string>("Result")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("result");

                    b.Property<Guid?>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("UserAgent")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("user_agent");

                    b.Property<Guid?>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_auth_login_events");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_auth_login_events_user_id");

                    b.HasIndex("TenantId", "UserId", "CreatedAt")
                        .HasDatabaseName("ix_auth_login_events_tenant_id_user_id_created_at");

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

            modelBuilder.Entity("Tiku.Domain.Tenancy.AuthSession", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset>("ExpiresAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("expires_at");

                    b.Property<string>("IpAddress")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("ip_address");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<Guid?>("ParentSessionId")
                        .HasColumnType("uuid")
                        .HasColumnName("parent_session_id");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("provider");

                    b.Property<string>("Realm")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("realm");

                    b.Property<Guid?>("ReplacedBySessionId")
                        .HasColumnType("uuid")
                        .HasColumnName("replaced_by_session_id");

                    b.Property<DateTimeOffset?>("RevokedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("revoked_at");

                    b.Property<string>("RevokedReason")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("revoked_reason");

                    b.Property<string>("SecurityStamp")
                        .IsRequired()
                        .HasMaxLength(128)
                        .HasColumnType("character varying(128)")
                        .HasColumnName("security_stamp");

                    b.Property<Guid?>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<Guid>("TokenFamilyId")
                        .HasColumnType("uuid")
                        .HasColumnName("token_family_id");

                    b.Property<string>("TokenHash")
                        .IsRequired()
                        .HasMaxLength(256)
                        .HasColumnType("character varying(256)")
                        .HasColumnName("token_hash");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("UserAgent")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("user_agent");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_auth_sessions");

                    b.HasIndex("TenantId")
                        .HasDatabaseName("ix_auth_sessions_tenant_id");

                    b.HasIndex("TokenHash")
                        .IsUnique()
                        .HasDatabaseName("ix_auth_sessions_token_hash")
                        .HasAnnotation("Tiku:GlobalUnique", true);

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_auth_sessions_user_id");

                    b.HasIndex("TokenFamilyId", "RevokedAt")
                        .HasDatabaseName("ix_auth_sessions_token_family_id_revoked_at");

                    b.HasIndex("Realm", "TenantId", "UserId", "ExpiresAt")
                        .HasDatabaseName("ix_auth_sessions_realm_tenant_id_user_id_expires_at")
                        .HasFilter("revoked_at is null");

                    b.ToTable("auth_sessions", null, t =>
                        {
                            t.HasCheckConstraint("ck_auth_sessions_realm_tenant", "(realm = 'tenant' and tenant_id is not null) or (realm = 'platform' and tenant_id is null)");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.SmsSendRateLimit", b =>
                {
                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Dimension")
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("dimension");

                    b.Property<string>("ScopeHash")
                        .HasMaxLength(128)
                        .HasColumnType("character varying(128)")
                        .HasColumnName("scope_hash");

                    b.Property<DateTimeOffset>("BucketStart")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("bucket_start");

                    b.Property<int>("RequestCount")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("integer")
                        .HasDefaultValue(0)
                        .HasColumnName("request_count");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("TenantId", "Dimension", "ScopeHash", "BucketStart")
                        .HasName("pk_sms_send_rate_limits");

                    b.HasIndex("UpdatedAt")
                        .HasDatabaseName("ix_sms_send_rate_limits_updated_at");

                    b.ToTable("sms_send_rate_limits", null, t =>
                        {
                            t.HasCheckConstraint("ck_sms_send_rate_limits_request_count", "request_count >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.SmsVerificationCode", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("Attempts")
                        .HasColumnType("integer")
                        .HasColumnName("attempts");

                    b.Property<string>("CodeHash")
                        .IsRequired()
                        .HasMaxLength(256)
                        .HasColumnType("character varying(256)")
                        .HasColumnName("code_hash");

                    b.Property<DateTimeOffset?>("ConsumedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("consumed_at");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset>("ExpiresAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("expires_at");

                    b.Property<string>("IpAddress")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("ip_address");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Phone")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("phone");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("provider");

                    b.Property<string>("Purpose")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("purpose");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("UserAgent")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("user_agent");

                    b.HasKey("Id")
                        .HasName("pk_sms_verification_codes");

                    b.HasIndex("TenantId", "Phone", "Purpose")
                        .IsUnique()
                        .HasDatabaseName("ix_sms_verification_codes_tenant_id_phone_purpose")
                        .HasFilter("consumed_at is null and status in ('pending', 'sent')");

                    b.HasIndex("TenantId", "Phone", "Purpose", "CreatedAt")
                        .HasDatabaseName("ix_sms_verification_codes_tenant_id_phone_purpose_created_at")
                        .HasFilter("consumed_at is null and status in ('pending', 'sent')");

                    b.HasIndex("TenantId", "Phone", "Purpose", "ExpiresAt")
                        .HasDatabaseName("ix_sms_verification_codes_tenant_id_phone_purpose_expires_at");

                    b.ToTable("sms_verification_codes", null, t =>
                        {
                            t.HasCheckConstraint("ck_sms_verification_codes_attempts", "attempts >= 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.Tenant", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("BillingStatus")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("billing_status");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<string>("LegalName")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("legal_name");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Mode")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("mode");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<Guid?>("OwnerUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("owner_user_id");

                    b.Property<string>("Slug")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("citext")
                        .HasColumnName("slug");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_tenants");

                    b.HasIndex("LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_tenants_legacy_id");

                    b.HasIndex("Mode")
                        .IsUnique()
                        .HasDatabaseName("ix_tenants_mode")
                        .HasFilter("mode = 'platform_owned'");

                    b.HasIndex("OwnerUserId")
                        .HasDatabaseName("ix_tenants_owner_user_id");

                    b.HasIndex("Slug")
                        .IsUnique()
                        .HasDatabaseName("ix_tenants_slug");

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

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantAuthPolicy", b =>
                {
                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<bool>("AllowExternalStudentSelfRegistration")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("boolean")
                        .HasDefaultValue(false)
                        .HasColumnName("allow_external_student_self_registration");

                    b.PrimitiveCollection<string[]>("AllowedStudentLoginMethods")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasColumnType("text[]")
                        .HasColumnName("allowed_student_login_methods")
                        .HasDefaultValueSql("ARRAY['password']::text[]");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("TenantId")
                        .HasName("pk_tenant_auth_policies");

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

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantBranding", b =>
                {
                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("BrandName")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("brand_name");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("FaviconUrl")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("favicon_url");

                    b.Property<string>("LogoUrl")
                        .HasMaxLength(2048)
                        .HasColumnType("character varying(2048)")
                        .HasColumnName("logo_url");

                    b.Property<string>("OrganizationName")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("organization_name");

                    b.Property<JsonElement>("PublicAssets")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("public_assets")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("ServiceAccountName")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("service_account_name");

                    b.Property<string>("ServiceWechat")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("service_wechat");

                    b.Property<string>("ShortName")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("short_name");

                    b.Property<string>("Slogan")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("slogan");

                    b.Property<JsonElement>("Theme")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("theme")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("TenantId")
                        .HasName("pk_tenant_branding");

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

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantClass", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Code")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("code");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<string>("LegacyId")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("legacy_id");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<Guid?>("RegionId")
                        .HasColumnType("uuid")
                        .HasColumnName("region_id");

                    b.Property<int>("SortOrder")
                        .HasColumnType("integer")
                        .HasColumnName("sort_order");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UpdatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("updated_by");

                    b.HasKey("Id")
                        .HasName("pk_tenant_classes");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_classes_tenant_id_id");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_tenant_classes_created_by");

                    b.HasIndex("UpdatedBy")
                        .HasDatabaseName("ix_tenant_classes_updated_by");

                    b.HasIndex("TenantId", "Code")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_classes_tenant_id_code")
                        .HasFilter("code is not null and code <> ''");

                    b.HasIndex("TenantId", "LegacyId")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_classes_tenant_id_legacy_id");

                    b.HasIndex("TenantId", "RegionId")
                        .HasDatabaseName("ix_tenant_classes_tenant_id_region_id")
                        .HasFilter("region_id is not null");

                    b.HasIndex("TenantId", "Status", "SortOrder", "CreatedAt")
                        .HasDatabaseName("ix_tenant_classes_tenant_id_status_sort_order_created_at");

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

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantClassMember", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid>("ClassId")
                        .HasColumnType("uuid")
                        .HasColumnName("class_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<DateTimeOffset>("JoinedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("joined_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset?>("LeftAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("left_at");

                    b.Property<string>("MemberType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("member_type");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UpdatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("updated_by");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_tenant_class_members");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_class_members_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_tenant_class_members_user_id");

                    b.HasIndex("TenantId", "ClassId", "Status", "MemberType")
                        .HasDatabaseName("ix_tenant_class_members_tenant_id_class_id_status_member_type");

                    b.HasIndex("TenantId", "ClassId", "UserId", "MemberType")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_class_members_tenant_id_class_id_user_id_member_type");

                    b.HasIndex("TenantId", "UserId", "Status", "MemberType")
                        .HasDatabaseName("ix_tenant_class_members_tenant_id_user_id_status_member_type");

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

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantDomain", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<DateTimeOffset?>("DnsVerifiedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("dns_verified_at");

                    b.Property<string>("DomainType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("domain_type");

                    b.Property<string>("Host")
                        .IsRequired()
                        .HasMaxLength(253)
                        .HasColumnType("citext")
                        .HasColumnName("host");

                    b.Property<bool>("IsPrimary")
                        .HasColumnType("boolean")
                        .HasColumnName("is_primary");

                    b.Property<DateTimeOffset?>("LastCheckedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("last_checked_at");

                    b.Property<string>("LastFailureReason")
                        .HasMaxLength(2000)
                        .HasColumnType("character varying(2000)")
                        .HasColumnName("last_failure_reason");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset?>("TlsReadyAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("tls_ready_at");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("VerificationToken")
                        .HasMaxLength(256)
                        .HasColumnType("character varying(256)")
                        .HasColumnName("verification_token");

                    b.Property<DateTimeOffset?>("VerifiedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("verified_at");

                    b.HasKey("Id")
                        .HasName("pk_tenant_domains");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_domains_tenant_id_id");

                    b.HasIndex("Host")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_domains_host")
                        .HasAnnotation("Tiku:GlobalUnique", true);

                    b.HasIndex("TenantId", "IsPrimary")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_domains_tenant_id_is_primary")
                        .HasFilter("is_primary");

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

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantExternalProvider", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Capability")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("capability");

                    b.Property<JsonElement>("ConfigPublic")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("config_public")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("DisplayName")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("display_name");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("Priority")
                        .HasColumnType("integer")
                        .HasColumnName("priority");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("provider");

                    b.Property<string>("SecretRef")
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("secret_ref");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_tenant_external_providers");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_external_providers_tenant_id_id");

                    b.HasIndex("TenantId", "Capability", "Provider")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_external_providers_tenant_id_capability_provider");

                    b.HasIndex("TenantId", "Capability", "Status", "Priority")
                        .HasDatabaseName("ix_tenant_external_providers_tenant_id_capability_status_prior~");

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

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantFrontendConfig", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("ConfigVersion")
                        .IsConcurrencyToken()
                        .HasColumnType("integer")
                        .HasColumnName("config_version");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("DraftBranding")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("draft_branding")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<JsonElement>("DraftFeatures")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("draft_features")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<JsonElement>("DraftHomeModules")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("draft_home_modules")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<JsonElement>("DraftNavigation")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("draft_navigation")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<JsonElement>("DraftTheme")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("draft_theme")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset?>("PublishedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("published_at");

                    b.Property<JsonElement>("PublishedBranding")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("published_branding")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<JsonElement>("PublishedFeatures")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("published_features")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<JsonElement>("PublishedHomeModules")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("published_home_modules")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<JsonElement>("PublishedNavigation")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("published_navigation")
                        .HasDefaultValueSql("'[]'::jsonb");

                    b.Property<JsonElement>("PublishedTheme")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("published_theme")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<int>("SchemaVersion")
                        .HasColumnType("integer")
                        .HasColumnName("schema_version");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_tenant_frontend_configs");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_frontend_configs_tenant_id_id");

                    b.HasIndex("TenantId")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_frontend_configs_tenant_id");

                    b.ToTable("tenant_frontend_configs", null, t =>
                        {
                            t.HasCheckConstraint("ck_tenant_frontend_configs_config_version", "config_version > 0");

                            t.HasCheckConstraint("ck_tenant_frontend_configs_schema_version", "schema_version > 0");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantMembership", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<string>("LegacyRole")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("legacy_role");

                    b.Property<string>("Role")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("role");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id")
                        .HasName("pk_tenant_memberships");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_memberships_tenant_id_id");

                    b.HasIndex("UserId")
                        .HasDatabaseName("ix_tenant_memberships_user_id");

                    b.HasIndex("TenantId", "UserId", "Role")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_memberships_tenant_id_user_id_role");

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

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantSecret", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<byte[]>("EncryptedPayload")
                        .IsRequired()
                        .HasColumnType("bytea")
                        .HasColumnName("encrypted_payload");

                    b.Property<string>("EncryptionKeyId")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("encryption_key_id");

                    b.Property<byte[]>("EncryptionNonce")
                        .IsRequired()
                        .HasColumnType("bytea")
                        .HasColumnName("encryption_nonce");

                    b.Property<byte[]>("EncryptionTag")
                        .IsRequired()
                        .HasColumnType("bytea")
                        .HasColumnName("encryption_tag");

                    b.Property<DateTimeOffset?>("ExpiresAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("expires_at");

                    b.Property<string>("Provider")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("provider");

                    b.Property<string>("Purpose")
                        .IsRequired()
                        .HasMaxLength(80)
                        .HasColumnType("character varying(80)")
                        .HasColumnName("purpose");

                    b.Property<DateTimeOffset?>("RotatedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("rotated_at");

                    b.Property<string>("SecretKey")
                        .IsRequired()
                        .HasMaxLength(120)
                        .HasColumnType("character varying(120)")
                        .HasColumnName("secret_key");

                    b.Property<string>("SecretRef")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("secret_ref");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("Id")
                        .HasName("pk_tenant_secrets");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_secrets_tenant_id_id");

                    b.HasIndex("TenantId", "SecretRef")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_secrets_tenant_id_secret_ref");

                    b.HasIndex("TenantId", "Purpose", "Provider", "SecretKey")
                        .IsUnique()
                        .HasDatabaseName("ix_tenant_secrets_tenant_id_purpose_provider_secret_key");

                    b.HasIndex("TenantId", "Purpose", "Provider", "Status")
                        .HasDatabaseName("ix_tenant_secrets_tenant_id_purpose_provider_status");

                    b.ToTable("tenant_secrets", null, t =>
                        {
                            t.HasCheckConstraint("ck_tenant_secrets_encryption_envelope", "octet_length(encrypted_payload) > 0 and octet_length(encryption_nonce) = 12 and octet_length(encryption_tag) = 16 and encryption_key_id <> ''");
                        });
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantSettings", b =>
                {
                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<JsonElement>("AdminFeatureFlags")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("admin_feature_flags")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<JsonElement>("FeatureFlags")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("feature_flags")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<JsonElement>("PublicConfig")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("public_config")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.HasKey("TenantId")
                        .HasName("pk_tenant_settings");

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

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantStudentFollowup", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid?>("AssignedToUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("assigned_to_user_id");

                    b.Property<Guid?>("ClassId")
                        .HasColumnType("uuid")
                        .HasColumnName("class_id");

                    b.Property<DateTimeOffset?>("CompletedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("completed_at");

                    b.Property<Guid?>("CompletedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("completed_by");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<string>("Description")
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<DateTimeOffset?>("DueAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("due_at");

                    b.Property<string>("FollowupType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("followup_type");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("Priority")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("priority");

                    b.Property<string>("Status")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("status");

                    b.Property<Guid>("StudentUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("student_user_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<string>("Title")
                        .IsRequired()
                        .HasMaxLength(300)
                        .HasColumnType("character varying(300)")
                        .HasColumnName("title");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UpdatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("updated_by");

                    b.HasKey("Id")
                        .HasName("pk_tenant_student_followups");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_student_followups_tenant_id_id");

                    b.HasIndex("AssignedToUserId")
                        .HasDatabaseName("ix_tenant_student_followups_assigned_to_user_id");

                    b.HasIndex("CompletedBy")
                        .HasDatabaseName("ix_tenant_student_followups_completed_by");

                    b.HasIndex("StudentUserId")
                        .HasDatabaseName("ix_tenant_student_followups_student_user_id");

                    b.HasIndex("TenantId", "AssignedToUserId", "Status", "DueAt")
                        .HasDatabaseName("ix_tenant_student_followups_tenant_id_assigned_to_user_id_stat~")
                        .HasFilter("assigned_to_user_id is not null");

                    b.HasIndex("TenantId", "ClassId", "Status", "DueAt")
                        .HasDatabaseName("ix_tenant_student_followups_tenant_id_class_id_status_due_at")
                        .HasFilter("class_id is not null");

                    b.HasIndex("TenantId", "StudentUserId", "Status", "DueAt", "CreatedAt")
                        .HasDatabaseName("ix_tenant_student_followups_tenant_id_student_user_id_status_d~");

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

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantStudentNote", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Content")
                        .IsRequired()
                        .HasColumnType("text")
                        .HasColumnName("content");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("CreatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("created_by");

                    b.Property<bool>("IsPinned")
                        .HasColumnType("boolean")
                        .HasColumnName("is_pinned");

                    b.Property<JsonElement>("Metadata")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("jsonb")
                        .HasColumnName("metadata")
                        .HasDefaultValueSql("'{}'::jsonb");

                    b.Property<string>("NoteType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("note_type");

                    b.Property<Guid>("StudentUserId")
                        .HasColumnType("uuid")
                        .HasColumnName("student_user_id");

                    b.Property<Guid>("TenantId")
                        .HasColumnType("uuid")
                        .HasColumnName("tenant_id");

                    b.Property<DateTimeOffset>("UpdatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("updated_at")
                        .HasDefaultValueSql("now()");

                    b.Property<Guid?>("UpdatedBy")
                        .HasColumnType("uuid")
                        .HasColumnName("updated_by");

                    b.Property<string>("Visibility")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("visibility");

                    b.HasKey("Id")
                        .HasName("pk_tenant_student_notes");

                    b.HasAlternateKey("TenantId", "Id")
                        .HasName("ak_tenant_student_notes_tenant_id_id");

                    b.HasIndex("CreatedBy")
                        .HasDatabaseName("ix_tenant_student_notes_created_by");

                    b.HasIndex("StudentUserId")
                        .HasDatabaseName("ix_tenant_student_notes_student_user_id");

                    b.HasIndex("UpdatedBy")
                        .HasDatabaseName("ix_tenant_student_notes_updated_by");

                    b.HasIndex("TenantId", "CreatedBy", "CreatedAt")
                        .HasDatabaseName("ix_tenant_student_notes_tenant_id_created_by_created_at")
                        .HasFilter("created_by is not null");

                    b.HasIndex("TenantId", "StudentUserId", "IsPinned", "CreatedAt")
                        .HasDatabaseName("ix_tenant_student_notes_tenant_id_student_user_id_is_pinned_cr~");

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

            modelBuilder.Entity("MassTransit.EntityFrameworkCoreIntegration.OutboxMessage", b =>
                {
                    b.HasOne("MassTransit.EntityFrameworkCoreIntegration.OutboxState", null)
                        .WithMany()
                        .HasForeignKey("OutboxId")
                        .HasConstraintName("fk_outbox_message_outbox_state_outbox_id");

                    b.HasOne("MassTransit.EntityFrameworkCoreIntegration.InboxState", null)
                        .WithMany()
                        .HasForeignKey("InboxMessageId", "InboxConsumerId")
                        .HasPrincipalKey("MessageId", "ConsumerId")
                        .HasConstraintName("fk_outbox_message_inbox_state_inbox_message_id_inbox_consumer_~");
                });

            modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_user_claims_users_user_id");
                });

            modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_user_logins_users_user_id");
                });

            modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_user_tokens_users_user_id");
                });

            modelBuilder.Entity("Tiku.Domain.Catalog.Category", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_categories_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.ModuleNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "NodeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_categories_module_nodes_tenant_id_node_id");

                    b.HasOne("Tiku.Domain.Catalog.Subject", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SubjectId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_categories_subjects_tenant_id_subject_id");
                });

            modelBuilder.Entity("Tiku.Domain.Catalog.Major", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_majors_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_majors_regions_tenant_id_region_id");

                    b.HasOne("Tiku.Domain.Catalog.School", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SchoolId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_majors_schools_tenant_id_school_id");
                });

            modelBuilder.Entity("Tiku.Domain.Catalog.ModuleNode", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_module_nodes_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.RegionModule", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ModuleId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_module_nodes_region_modules_tenant_id_module_id");

                    b.HasOne("Tiku.Domain.Catalog.ModuleNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ParentId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_module_nodes_module_nodes_tenant_id_parent_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_module_nodes_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Catalog.QuestionTaxonomyAssignment", b =>
                {
                    b.HasOne("Tiku.Domain.Catalog.TaxonomyNode", null)
                        .WithMany()
                        .HasForeignKey("TaxonomyOwnerTenantId", "TaxonomyNodeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_question_taxonomy_assignments_taxonomy_nodes_taxonomy_owner~");

                    b.HasOne("Tiku.Domain.QuestionBanks.Question", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "QuestionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_question_taxonomy_assignments_questions_tenant_id_question_~");
                });

            modelBuilder.Entity("Tiku.Domain.Catalog.Region", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_regions_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Catalog.RegionModule", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_region_modules_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_region_modules_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Catalog.School", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_schools_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.RegionModule", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ModuleId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_schools_region_modules_tenant_id_module_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_schools_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Catalog.ScorelineField", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_scoreline_fields_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_scoreline_fields_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Catalog.ScorelineRecord", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_scoreline_records_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Major", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "MajorId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_scoreline_records_majors_tenant_id_major_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_scoreline_records_regions_tenant_id_region_id");

                    b.HasOne("Tiku.Domain.Catalog.School", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SchoolId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_scoreline_records_schools_tenant_id_school_id");
                });

            modelBuilder.Entity("Tiku.Domain.Catalog.Subject", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_subjects_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Major", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "MajorId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_subjects_majors_tenant_id_major_id");

                    b.HasOne("Tiku.Domain.Catalog.RegionModule", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ModuleId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_subjects_region_modules_tenant_id_module_id");

                    b.HasOne("Tiku.Domain.Catalog.ModuleNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "NodeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_subjects_module_nodes_tenant_id_node_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_subjects_regions_tenant_id_region_id");

                    b.HasOne("Tiku.Domain.Catalog.School", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SchoolId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_subjects_schools_tenant_id_school_id");
                });

            modelBuilder.Entity("Tiku.Domain.Catalog.TaxonomyNode", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_taxonomy_nodes_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.TaxonomyNode", null)
                        .WithMany()
                        .HasForeignKey("ParentOwnerTenantId", "ParentId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_taxonomy_nodes_taxonomy_nodes_parent_owner_tenant_id_parent~");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.ActivationCode", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("AgentUserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_activation_codes_users_agent_user_id");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_activation_codes_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UsedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_activation_codes_users_used_by");

                    b.HasOne("Tiku.Domain.Commerce.CodeBatch", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "BatchId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_activation_codes_code_batches_tenant_id_batch_id");

                    b.HasOne("Tiku.Domain.Commerce.CouponRedemption", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "CouponRedemptionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_activation_codes_coupon_redemptions_tenant_id_coupon_redemp~");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "UsedRegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_activation_codes_regions_tenant_id_used_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.CodeBatch", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_code_batches_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceAdjustmentVoucher", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_adjustment_vouchers_users_created_by");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ReviewedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_adjustment_vouchers_users_reviewed_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commerce_adjustment_vouchers_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Commerce.CommerceReconciliationBatch", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "BatchId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_adjustment_vouchers_commerce_reconciliation_batche~");

                    b.HasOne("Tiku.Domain.Commerce.CommerceReconciliationIssue", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "IssueId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_adjustment_vouchers_commerce_reconciliation_issues~");

                    b.HasOne("Tiku.Domain.Commerce.CommerceReconciliationItem", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ItemId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_adjustment_vouchers_commerce_reconciliation_items_~");

                    b.HasOne("Tiku.Domain.Commerce.Order", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "OrderId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_adjustment_vouchers_orders_tenant_id_order_id");

                    b.HasOne("Tiku.Domain.Commerce.Payment", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PaymentId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_adjustment_vouchers_payments_tenant_id_payment_id");

                    b.HasOne("Tiku.Domain.Commerce.CommerceRefundRequest", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RefundRequestId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_adjustment_vouchers_commerce_refund_requests_tenan~");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceAdjustmentVoucherEvent", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ActorUserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_adjustment_voucher_events_users_actor_user_id");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commerce_adjustment_voucher_events_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Commerce.CommerceAdjustmentVoucher", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "VoucherId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commerce_adjustment_voucher_events_commerce_adjustment_vouc~");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceReconciliationBatch", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_reconciliation_batches_users_created_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commerce_reconciliation_batches_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceReconciliationIssue", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("AssignedTo")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_reconciliation_issues_users_assigned_to");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_reconciliation_issues_users_created_by");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ResolvedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_reconciliation_issues_users_resolved_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commerce_reconciliation_issues_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Commerce.CommerceReconciliationBatch", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "BatchId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_commerce_reconciliation_issues_commerce_reconciliation_batc~");

                    b.HasOne("Tiku.Domain.Commerce.CommerceReconciliationItem", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ItemId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_commerce_reconciliation_issues_commerce_reconciliation_item~");

                    b.HasOne("Tiku.Domain.Commerce.Order", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "OrderId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_commerce_reconciliation_issues_orders_tenant_id_order_id");

                    b.HasOne("Tiku.Domain.Commerce.Payment", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PaymentId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_commerce_reconciliation_issues_payments_tenant_id_payment_id");

                    b.HasOne("Tiku.Domain.Commerce.CommerceRefundRequest", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RefundRequestId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_commerce_reconciliation_issues_commerce_refund_requests_ten~");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceReconciliationIssueEvent", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ActorUserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_reconciliation_issue_events_users_actor_user_id");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commerce_reconciliation_issue_events_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Commerce.CommerceReconciliationIssue", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "IssueId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commerce_reconciliation_issue_events_commerce_reconciliatio~");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceReconciliationItem", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commerce_reconciliation_items_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Commerce.CommerceReconciliationBatch", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "BatchId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commerce_reconciliation_items_commerce_reconciliation_batch~");

                    b.HasOne("Tiku.Domain.Commerce.Order", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "OrderId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_commerce_reconciliation_items_orders_tenant_id_order_id");

                    b.HasOne("Tiku.Domain.Commerce.Payment", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PaymentId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_commerce_reconciliation_items_payments_tenant_id_payment_id");

                    b.HasOne("Tiku.Domain.Commerce.CommerceRefundRequest", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RefundRequestId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_commerce_reconciliation_items_commerce_refund_requests_tena~");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceRefundEvent", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ActorUserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_refund_events_users_actor_user_id");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commerce_refund_events_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Commerce.CommerceRefundRequest", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RefundRequestId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commerce_refund_events_commerce_refund_requests_tenant_id_r~");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.CommerceRefundRequest", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ProcessedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_refund_requests_users_processed_by");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("RequestedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_refund_requests_users_requested_by");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ReviewedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commerce_refund_requests_users_reviewed_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commerce_refund_requests_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Commerce.Order", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "OrderId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commerce_refund_requests_orders_tenant_id_order_id");

                    b.HasOne("Tiku.Domain.Commerce.Payment", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PaymentId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_commerce_refund_requests_payments_tenant_id_payment_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.Coupon", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_coupons_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Commerce.SvipPlan", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PlanId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_coupons_svip_plans_tenant_id_plan_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.CouponRedemption", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_coupon_redemptions_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_coupon_redemptions_users_user_id");

                    b.HasOne("Tiku.Domain.Commerce.Coupon", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "CouponId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_coupon_redemptions_coupons_tenant_id_coupon_id");

                    b.HasOne("Tiku.Domain.Commerce.Order", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "OrderId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_coupon_redemptions_orders_tenant_id_order_id");

                    b.HasOne("Tiku.Domain.Commerce.SvipPlan", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PlanId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_coupon_redemptions_svip_plans_tenant_id_plan_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_coupon_redemptions_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.Entitlement", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("RevokedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_entitlements_users_revoked_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_entitlements_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_entitlements_users_user_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.Order", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_orders_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_orders_users_user_id");

                    b.HasOne("Tiku.Domain.Commerce.SvipPlan", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PlanId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_orders_svip_plans_tenant_id_plan_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_orders_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.OrderItem", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_order_items_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Commerce.Order", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "OrderId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_order_items_orders_tenant_id_order_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.Payment", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_payments_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Commerce.Order", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "OrderId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_payments_orders_tenant_id_order_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.PaymentEvent", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_payment_events_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Commerce.Payment", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PaymentId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_payment_events_payments_tenant_id_payment_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.PointActivityClaim", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_point_activity_claims_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_point_activity_claims_users_user_id");

                    b.HasOne("Tiku.Domain.Commerce.PointActivityTask", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "TaskId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_point_activity_claims_point_activity_tasks_tenant_id_task_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.PointActivityTask", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_point_activity_tasks_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.PointExchangeItem", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_point_exchange_items_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_point_exchange_items_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.PointExchangeOrder", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_point_exchange_orders_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_point_exchange_orders_users_user_id");

                    b.HasOne("Tiku.Domain.Commerce.PointExchangeItem", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ItemId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_point_exchange_orders_point_exchange_items_tenant_id_item_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.Product", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_products_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_products_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Commerce.SvipPlan", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_svip_plans_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_svip_plans_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.AiRecommendationReport", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_ai_recommendation_reports_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_ai_recommendation_reports_users_user_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_ai_recommendation_reports_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.AppAsset", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_app_assets_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.ContentAsset", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_content_assets_users_created_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_content_assets_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UpdatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_content_assets_users_updated_by");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("VerifiedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_content_assets_users_verified_by");

                    b.HasOne("Tiku.Domain.Catalog.Category", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "CategoryId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_content_assets_categories_tenant_id_category_id");

                    b.HasOne("Tiku.Domain.Content.ContentNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ContentNodeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_content_assets_content_nodes_tenant_id_content_node_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_content_assets_regions_tenant_id_region_id");

                    b.HasOne("Tiku.Domain.Catalog.Subject", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SubjectId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_content_assets_subjects_tenant_id_subject_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.ContentAssetAccessEvent", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_content_asset_access_events_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_content_asset_access_events_users_user_id");

                    b.HasOne("Tiku.Domain.Content.ContentAsset", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "AssetId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_content_asset_access_events_content_assets_tenant_id_asset_~");
                });

            modelBuilder.Entity("Tiku.Domain.Content.ContentAssetSecurityScanEvent", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_content_asset_security_scan_events_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Content.ContentAsset", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "AssetId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_content_asset_security_scan_events_content_assets_tenant_id~");
                });

            modelBuilder.Entity("Tiku.Domain.Content.ContentEntry", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_content_entries_users_created_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_content_entries_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UpdatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_content_entries_users_updated_by");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_content_entries_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.ContentImportIssue", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_content_import_issues_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Content.ContentImportItem", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ItemId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_content_import_issues_content_import_items_tenant_id_item_id");

                    b.HasOne("Tiku.Domain.Content.ContentImportJob", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "JobId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_content_import_issues_content_import_jobs_tenant_id_job_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.ContentImportItem", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_content_import_items_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Content.ContentImportJob", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "JobId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_content_import_items_content_import_jobs_tenant_id_job_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.ContentImportJob", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_content_import_jobs_users_created_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_content_import_jobs_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Category", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "TargetCategoryId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_content_import_jobs_categories_tenant_id_target_category_id");

                    b.HasOne("Tiku.Domain.Content.ContentNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "TargetContentNodeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_content_import_jobs_content_nodes_tenant_id_target_content_~");

                    b.HasOne("Tiku.Domain.QuestionBanks.QuestionBank", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "TargetQuestionBankId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_content_import_jobs_question_banks_tenant_id_target_questio~");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "TargetRegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_content_import_jobs_regions_tenant_id_target_region_id");

                    b.HasOne("Tiku.Domain.Catalog.Subject", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "TargetSubjectId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_content_import_jobs_subjects_tenant_id_target_subject_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.ContentNode", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_content_nodes_users_created_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_content_nodes_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UpdatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_content_nodes_users_updated_by");

                    b.HasOne("Tiku.Domain.Content.ContentEntry", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "EntryId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_content_nodes_content_entries_tenant_id_entry_id");

                    b.HasOne("Tiku.Domain.Content.ContentNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ParentId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_content_nodes_content_nodes_tenant_id_parent_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_content_nodes_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.HandbookChapter", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_handbook_chapters_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Content.ContentNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ContentNodeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_handbook_chapters_content_nodes_tenant_id_content_node_id");

                    b.HasOne("Tiku.Domain.Content.ContentEntry", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "EntryId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_handbook_chapters_content_entries_tenant_id_entry_id");

                    b.HasOne("Tiku.Domain.Content.HandbookSubject", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SubjectId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_handbook_chapters_handbook_subjects_tenant_id_subject_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.HandbookEntry", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_handbook_entries_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Content.HandbookChapter", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ChapterId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_handbook_entries_handbook_chapters_tenant_id_chapter_id");

                    b.HasOne("Tiku.Domain.Content.ContentNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ContentNodeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_handbook_entries_content_nodes_tenant_id_content_node_id");

                    b.HasOne("Tiku.Domain.Content.ContentEntry", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "EntryId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_handbook_entries_content_entries_tenant_id_entry_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.HandbookSubject", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_handbook_subjects_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Content.ContentNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ContentNodeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_handbook_subjects_content_nodes_tenant_id_content_node_id");

                    b.HasOne("Tiku.Domain.Content.ContentEntry", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "EntryId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_handbook_subjects_content_entries_tenant_id_entry_id");

                    b.HasOne("Tiku.Domain.Catalog.Major", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "MajorId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_handbook_subjects_majors_tenant_id_major_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_handbook_subjects_regions_tenant_id_region_id");

                    b.HasOne("Tiku.Domain.Catalog.School", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SchoolId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_handbook_subjects_schools_tenant_id_school_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.ImageAsset", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_images_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.PracticeBlueprint", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_practice_blueprints_users_created_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_practice_blueprints_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UpdatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_practice_blueprints_users_updated_by");

                    b.HasOne("Tiku.Domain.Content.QuestionCollection", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "CollectionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_practice_blueprints_question_collections_tenant_id_collecti~");

                    b.HasOne("Tiku.Domain.Content.ContentEntry", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "EntryId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_practice_blueprints_content_entries_tenant_id_entry_id");

                    b.HasOne("Tiku.Domain.Content.ContentNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "NodeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_practice_blueprints_content_nodes_tenant_id_node_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_practice_blueprints_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.QuestionCollection", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_question_collections_users_created_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_question_collections_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UpdatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_question_collections_users_updated_by");

                    b.HasOne("Tiku.Domain.Catalog.Category", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "CategoryId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_question_collections_categories_tenant_id_category_id");

                    b.HasOne("Tiku.Domain.Content.ContentEntry", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "EntryId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_question_collections_content_entries_tenant_id_entry_id");

                    b.HasOne("Tiku.Domain.Content.ContentNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "NodeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_question_collections_content_nodes_tenant_id_node_id");

                    b.HasOne("Tiku.Domain.QuestionBanks.QuestionBank", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "QuestionBankId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_question_collections_question_banks_tenant_id_question_bank~");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_question_collections_regions_tenant_id_region_id");

                    b.HasOne("Tiku.Domain.Catalog.Subject", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SubjectId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_question_collections_subjects_tenant_id_subject_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.QuestionCollectionItem", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_question_collection_items_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.QuestionBanks.Question", null)
                        .WithMany()
                        .HasForeignKey("QuestionOwnerTenantId", "QuestionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_question_collection_items_questions_question_owner_tenant_i~");

                    b.HasOne("Tiku.Domain.Content.QuestionCollection", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "CollectionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_question_collection_items_question_collections_tenant_id_co~");

                    b.HasOne("Tiku.Domain.Content.TenantQuestionReference", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "QuestionReferenceId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_question_collection_items_tenant_question_references_tenant~");
                });

            modelBuilder.Entity("Tiku.Domain.Content.QuestionTypeGroup", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_question_type_groups_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Subject", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SubjectId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_question_type_groups_subjects_tenant_id_subject_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.QuestionVideo", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_question_videos_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.QuestionBanks.Question", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "QuestionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_question_videos_questions_tenant_id_question_id");

                    b.HasOne("Tiku.Domain.Content.VideoExplanation", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "VideoId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_question_videos_video_explanations_tenant_id_video_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.SubjectShare", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_subject_shares_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Subject", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SourceSubjectId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_subject_shares_subjects_tenant_id_source_subject_id");

                    b.HasOne("Tiku.Domain.Catalog.Subject", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "TargetSubjectId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_subject_shares_subjects_tenant_id_target_subject_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.TenantQuestionBankPreference", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_question_bank_preferences_users_created_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_question_bank_preferences_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UpdatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_question_bank_preferences_users_updated_by");

                    b.HasOne("Tiku.Domain.QuestionBanks.QuestionBank", null)
                        .WithMany()
                        .HasForeignKey("QuestionBankOwnerTenantId", "QuestionBankId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_question_bank_preferences_question_banks_question_ba~");
                });

            modelBuilder.Entity("Tiku.Domain.Content.TenantQuestionReference", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_question_references_users_created_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_question_references_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.QuestionBanks.Question", null)
                        .WithMany()
                        .HasForeignKey("QuestionOwnerTenantId", "QuestionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_question_references_questions_question_owner_tenant_~");
                });

            modelBuilder.Entity("Tiku.Domain.Content.UserWordFavorite", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_user_word_favorites_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_user_word_favorites_users_user_id");

                    b.HasOne("Tiku.Domain.Content.VocabularyWord", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "WordId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_user_word_favorites_vocabulary_words_tenant_id_word_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.UserWordProgress", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_user_word_progress_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_user_word_progress_users_user_id");

                    b.HasOne("Tiku.Domain.Content.VocabularyWord", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "WordId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_user_word_progress_vocabulary_words_tenant_id_word_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.VideoExplanation", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_video_explanations_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Subject", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SubjectId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_video_explanations_subjects_tenant_id_subject_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.VideoPlaybackProgress", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_video_playback_progress_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_video_playback_progress_users_user_id");

                    b.HasOne("Tiku.Domain.QuestionBanks.Question", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "QuestionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_video_playback_progress_questions_tenant_id_question_id");

                    b.HasOne("Tiku.Domain.Content.VideoExplanation", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "VideoId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_video_playback_progress_video_explanations_tenant_id_video_~");
                });

            modelBuilder.Entity("Tiku.Domain.Content.VocabularyUnit", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_vocabulary_units_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Content.ContentNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ContentNodeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_vocabulary_units_content_nodes_tenant_id_content_node_id");

                    b.HasOne("Tiku.Domain.Content.ContentEntry", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "EntryId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_vocabulary_units_content_entries_tenant_id_entry_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_vocabulary_units_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Content.VocabularyWord", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_vocabulary_words_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Content.ContentNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ContentNodeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_vocabulary_words_content_nodes_tenant_id_content_node_id");

                    b.HasOne("Tiku.Domain.Content.ContentEntry", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "EntryId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_vocabulary_words_content_entries_tenant_id_entry_id");

                    b.HasOne("Tiku.Domain.Content.VocabularyUnit", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "UnitId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_vocabulary_words_vocabulary_units_tenant_id_unit_id");
                });

            modelBuilder.Entity("Tiku.Domain.Growth.CommissionSettlement", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("GeneratedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commission_settlements_users_generated_by");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("PaidBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commission_settlements_users_paid_by");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ReferrerUserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commission_settlements_users_referrer_user_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ReviewedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commission_settlements_users_reviewed_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commission_settlements_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Growth.CommissionSettlementExportEvent", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ExportedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commission_settlement_export_events_users_exported_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commission_settlement_export_events_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Growth.CommissionSettlement", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SettlementId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commission_settlement_export_events_commission_settlements_~");
                });

            modelBuilder.Entity("Tiku.Domain.Growth.CommissionSettlementItem", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ReferrerUserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commission_settlement_items_users_referrer_user_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("StudentUserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commission_settlement_items_users_student_user_id");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commission_settlement_items_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Growth.CommissionSettlement", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SettlementId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commission_settlement_items_commission_settlements_tenant_i~");
                });

            modelBuilder.Entity("Tiku.Domain.Growth.CommissionSettlementProof", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ReviewedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commission_settlement_proofs_users_reviewed_by");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("SubmittedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commission_settlement_proofs_users_submitted_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commission_settlement_proofs_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Content.ContentAsset", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "AssetId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_commission_settlement_proofs_content_assets_tenant_id_asset~");

                    b.HasOne("Tiku.Domain.Growth.CommissionSettlement", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SettlementId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_commission_settlement_proofs_commission_settlements_tenant_~");
                });

            modelBuilder.Entity("Tiku.Domain.Growth.CrmConfig", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_crm_config_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Growth.CrmWebhookLog", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_crm_webhook_log_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Growth.CrmWebhookQueueItem", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_crm_webhook_queue_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Growth.ReferralCode", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_referral_codes_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_referral_codes_users_user_id");
                });

            modelBuilder.Entity("Tiku.Domain.Growth.ReferralLead", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("AssignedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_referral_leads_users_assigned_by");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("AssignedToUserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_referral_leads_users_assigned_to_user_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ReferrerUserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_referral_leads_users_referrer_user_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("StudentUserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_referral_leads_users_student_user_id");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_referral_leads_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Growth.ReferralTrack", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "FirstTrackId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_referral_leads_referral_tracks_tenant_id_first_track_id");
                });

            modelBuilder.Entity("Tiku.Domain.Growth.ReferralQrcode", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_referral_qrcodes_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_referral_qrcodes_users_user_id");
                });

            modelBuilder.Entity("Tiku.Domain.Growth.ReferralTeamEdge", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("LeaderUserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_referral_team_edges_users_leader_user_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("MemberUserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_referral_team_edges_users_member_user_id");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_referral_team_edges_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Growth.ReferralTrack", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ReferrerUserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_referral_tracks_users_referrer_user_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("TargetUserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_referral_tracks_users_target_user_id");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_referral_tracks_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Growth.ReferralLead", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "LeadId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_referral_tracks_referral_leads_tenant_id_lead_id");
                });

            modelBuilder.Entity("Tiku.Domain.Growth.TenantCommissionSetting", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_commission_settings_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UpdatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_commission_settings_users_updated_by");
                });

            modelBuilder.Entity("Tiku.Domain.Identity.StudentProfile", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_student_profiles_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_student_profiles_users_user_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_student_profiles_regions_tenant_id_region_id");

                    b.HasOne("Tiku.Domain.Catalog.Major", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SelectedMajorId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_student_profiles_majors_tenant_id_selected_major_id");

                    b.HasOne("Tiku.Domain.Catalog.School", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SelectedSchoolId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_student_profiles_schools_tenant_id_selected_school_id");
                });

            modelBuilder.Entity("Tiku.Domain.Identity.UserIdentity", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_user_identities_users_user_id");
                });

            modelBuilder.Entity("Tiku.Domain.Import.PocketBaseImportIssue", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_pb_import_issues_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Import.PocketBaseImportRun", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RunId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_pb_import_issues_pb_import_runs_tenant_id_run_id");
                });

            modelBuilder.Entity("Tiku.Domain.Import.PocketBaseImportRun", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_pb_import_runs_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Import.PocketBaseRawRecord", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_pb_raw_records_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Import.PocketBaseImportRun", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RunId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_pb_raw_records_pb_import_runs_tenant_id_run_id");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.AnswerRecord", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_answer_records_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_answer_records_users_user_id");

                    b.HasOne("Tiku.Domain.Learning.PracticeSessionQuestion", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PracticeSessionId", "SessionQuestionId")
                        .HasPrincipalKey("TenantId", "PracticeSessionId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_answer_records_practice_session_questions_tenant_id_practic~");

                    b.HasOne("Tiku.Domain.Learning.PracticeSession", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "UserId", "PracticeSessionId")
                        .HasPrincipalKey("TenantId", "UserId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_answer_records_practice_sessions_tenant_id_user_id_practice~");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.DashboardDailyStat", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_dashboard_daily_stats_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_dashboard_daily_stats_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.ExamDate", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_exam_dates_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_exam_dates_regions_tenant_id_region_id");

                    b.HasOne("Tiku.Domain.Catalog.School", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SchoolId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_exam_dates_schools_tenant_id_school_id");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.FavoriteQuestion", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_favorite_questions_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_favorite_questions_users_user_id");

                    b.HasOne("Tiku.Domain.QuestionBanks.Question", null)
                        .WithMany()
                        .HasForeignKey("QuestionOwnerTenantId", "QuestionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_favorite_questions_questions_question_owner_tenant_id_quest~");

                    b.HasOne("Tiku.Domain.Content.TenantQuestionReference", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "QuestionReferenceId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_favorite_questions_tenant_question_references_tenant_id_que~");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.PracticeAccessEvent", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_practice_access_events_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_practice_access_events_users_user_id");

                    b.HasOne("Tiku.Domain.Learning.PracticeSession", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PracticeSessionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_practice_access_events_practice_sessions_tenant_id_practice~");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.PracticeDailyUsage", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_practice_daily_usage_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_practice_daily_usage_users_user_id");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.PracticeSession", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_practice_sessions_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_practice_sessions_users_user_id");

                    b.HasOne("Tiku.Domain.Content.PracticeBlueprint", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "BlueprintId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_practice_sessions_practice_blueprints_tenant_id_blueprint_id");

                    b.HasOne("Tiku.Domain.Content.QuestionCollection", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "CollectionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_practice_sessions_question_collections_tenant_id_collection~");

                    b.HasOne("Tiku.Domain.Content.ContentNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ContentNodeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_practice_sessions_content_nodes_tenant_id_content_node_id");

                    b.HasOne("Tiku.Domain.Content.ContentEntry", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "EntryId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_practice_sessions_content_entries_tenant_id_entry_id");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.PracticeSessionQuestion", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_practice_session_questions_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Learning.PracticeSession", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PracticeSessionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_practice_session_questions_practice_sessions_tenant_id_prac~");

                    b.HasOne("Tiku.Domain.QuestionBanks.QuestionVersion", null)
                        .WithMany()
                        .HasForeignKey("QuestionOwnerTenantId", "QuestionId", "QuestionVersionId")
                        .HasPrincipalKey("TenantId", "QuestionId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_practice_session_questions_question_versions_question_owner~");

                    b.HasOne("Tiku.Domain.Content.TenantQuestionReference", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "QuestionOwnerTenantId", "QuestionId")
                        .HasPrincipalKey("TenantId", "QuestionOwnerTenantId", "QuestionId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_practice_session_questions_tenant_question_references_tenan~");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.PracticeSessionReport", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_practice_session_reports_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_practice_session_reports_users_user_id");

                    b.HasOne("Tiku.Domain.Content.PracticeBlueprint", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "BlueprintId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_practice_session_reports_practice_blueprints_tenant_id_blue~");

                    b.HasOne("Tiku.Domain.Content.QuestionCollection", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "CollectionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_practice_session_reports_question_collections_tenant_id_col~");

                    b.HasOne("Tiku.Domain.Learning.PracticeSession", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PracticeSessionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_practice_session_reports_practice_sessions_tenant_id_practi~");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.PracticeSessionReportSection", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_practice_session_report_sections_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Learning.PracticeSession", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PracticeSessionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_practice_session_report_sections_practice_sessions_tenant_i~");

                    b.HasOne("Tiku.Domain.Learning.PracticeSessionReport", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ReportId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_practice_session_report_sections_practice_session_reports_t~");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.RecentPractice", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_recent_practices_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_recent_practices_users_user_id");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.Report", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("HandledBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_reports_users_handled_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_reports_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_reports_users_user_id");

                    b.HasOne("Tiku.Domain.QuestionBanks.Question", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "QuestionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_reports_questions_tenant_id_question_id");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.ReportStatusEvent", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ActorUserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_report_status_events_users_actor_user_id");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_report_status_events_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Learning.Report", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ReportId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_report_status_events_reports_tenant_id_report_id");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.RevenueDailyStat", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_revenue_daily_stats_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_revenue_daily_stats_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.UserScoreEvent", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_user_score_events_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_user_score_events_users_user_id");
                });

            modelBuilder.Entity("Tiku.Domain.Learning.WrongQuestion", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_wrong_questions_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_wrong_questions_users_user_id");

                    b.HasOne("Tiku.Domain.QuestionBanks.Question", null)
                        .WithMany()
                        .HasForeignKey("QuestionOwnerTenantId", "QuestionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_wrong_questions_questions_question_owner_tenant_id_question~");

                    b.HasOne("Tiku.Domain.Content.TenantQuestionReference", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "QuestionReferenceId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_wrong_questions_tenant_question_references_tenant_id_questi~");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.Announcement", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_announcements_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.AuditLog", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ActorUserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_audit_logs_users_actor_user_id");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_audit_logs_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.BackendMenu", b =>
                {
                    b.HasOne("Tiku.Domain.Operations.BackendPermission", null)
                        .WithMany()
                        .HasForeignKey("PermissionCode")
                        .HasPrincipalKey("Code")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_backend_menus_backend_permissions_permission_code");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.BackendPermission", b =>
                {
                    b.HasOne("Tiku.Domain.Platform.PermissionModule", null)
                        .WithMany()
                        .HasForeignKey("PermissionModuleCode")
                        .HasPrincipalKey("Code")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_backend_permissions_permission_modules_permission_module_co~");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.BackgroundJob", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_background_jobs_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Content.ContentAsset", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "OutputAssetId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_background_jobs_content_assets_tenant_id_output_asset_id");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.Badge", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_badges_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.Banner", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_banners_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_banners_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.Faq", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_faqs_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_faqs_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.PlatformBackendRoleMenu", b =>
                {
                    b.HasOne("Tiku.Domain.Operations.BackendMenu", null)
                        .WithMany()
                        .HasForeignKey("MenuCode")
                        .HasPrincipalKey("Code")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_platform_backend_role_menus_backend_menus_menu_code");

                    b.HasOne("Tiku.Domain.Operations.PlatformBackendRole", null)
                        .WithMany()
                        .HasForeignKey("RoleId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_backend_role_menus_platform_backend_roles_role_id");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.PlatformBackendRolePermission", b =>
                {
                    b.HasOne("Tiku.Domain.Operations.BackendPermission", null)
                        .WithMany()
                        .HasForeignKey("PermissionCode")
                        .HasPrincipalKey("Code")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_platform_backend_role_permissions_backend_permissions_permi~");

                    b.HasOne("Tiku.Domain.Operations.PlatformBackendRole", null)
                        .WithMany()
                        .HasForeignKey("RoleId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_backend_role_permissions_platform_backend_roles_ro~");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.PlatformBackendUserRole", b =>
                {
                    b.HasOne("Tiku.Domain.Operations.PlatformBackendRole", null)
                        .WithMany()
                        .HasForeignKey("RoleId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_backend_user_roles_platform_backend_roles_role_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_backend_user_roles_users_user_id");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.TenantBackendRole", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_backend_roles_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.TenantBackendRoleMenu", b =>
                {
                    b.HasOne("Tiku.Domain.Operations.BackendMenu", null)
                        .WithMany()
                        .HasForeignKey("MenuCode")
                        .HasPrincipalKey("Code")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_backend_role_menus_backend_menus_menu_code");

                    b.HasOne("Tiku.Domain.Operations.TenantBackendRole", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RoleId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_backend_role_menus_tenant_backend_roles_tenant_id_ro~");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.TenantBackendRolePermission", b =>
                {
                    b.HasOne("Tiku.Domain.Operations.BackendPermission", null)
                        .WithMany()
                        .HasForeignKey("PermissionCode")
                        .HasPrincipalKey("Code")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_backend_role_permissions_backend_permissions_permiss~");

                    b.HasOne("Tiku.Domain.Operations.TenantBackendRole", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RoleId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_backend_role_permissions_tenant_backend_roles_tenant~");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.TenantBackendUserRole", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_backend_user_roles_users_user_id");

                    b.HasOne("Tiku.Domain.Operations.TenantBackendRole", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RoleId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_backend_user_roles_tenant_backend_roles_tenant_id_ro~");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.TenantContentNotification", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_content_notifications_users_created_by");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ReadBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_content_notifications_users_read_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_content_notifications_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.QuestionBanks.QuestionBank", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SourceQuestionBankId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_tenant_content_notifications_question_banks_tenant_id_sourc~");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.TenantThemeConfig", b =>
                {
                    b.HasOne("Tiku.Domain.Operations.TenantThemeTemplate", null)
                        .WithMany()
                        .HasForeignKey("ActiveTemplateCode")
                        .HasPrincipalKey("Code")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_theme_configs_tenant_theme_templates_active_template~");

                    b.HasOne("Tiku.Domain.Operations.TenantThemeTemplate", null)
                        .WithMany()
                        .HasForeignKey("DraftTemplateCode")
                        .HasPrincipalKey("Code")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_theme_configs_tenant_theme_templates_draft_template_~");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("DraftUpdatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_theme_configs_users_draft_updated_by");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("PublishedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_theme_configs_users_published_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_theme_configs_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.UserBadge", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("GrantedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_user_badges_users_granted_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_user_badges_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_user_badges_users_user_id");

                    b.HasOne("Tiku.Domain.Operations.Badge", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "BadgeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_user_badges_badges_tenant_id_badge_id");
                });

            modelBuilder.Entity("Tiku.Domain.Operations.UserNotification", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_user_notifications_users_created_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_user_notifications_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_user_notifications_users_user_id");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PermissionModule", b =>
                {
                    b.HasOne("Tiku.Domain.Platform.SaasFeature", null)
                        .WithMany()
                        .HasForeignKey("RequiredFeatureCode")
                        .HasPrincipalKey("Code")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_permission_modules_saas_features_required_feature_code");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformAuditAlert", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("AcknowledgedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_platform_audit_alerts_users_acknowledged_by");

                    b.HasOne("Tiku.Domain.Operations.AuditLog", null)
                        .WithMany()
                        .HasForeignKey("AuditLogId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_audit_alerts_audit_logs_audit_log_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("ResolvedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_platform_audit_alerts_users_resolved_by");

                    b.HasOne("Tiku.Domain.Platform.PlatformAuditAlertRule", null)
                        .WithMany()
                        .HasForeignKey("RuleId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_audit_alerts_platform_audit_alert_rules_rule_id");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_platform_audit_alerts_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformAuditAlertRule", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_platform_audit_alert_rules_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingDunningNotificationEvent", b =>
                {
                    b.HasOne("Tiku.Domain.Platform.PlatformBillingDunningNotificationChannel", null)
                        .WithMany()
                        .HasForeignKey("ChannelId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_dunning_events_channel");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_dunning_notification_events_tenants_tenant~");

                    b.HasOne("Tiku.Domain.Platform.PlatformBillingInvoice", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "InvoiceId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_dunning_events_invoice");

                    b.HasOne("Tiku.Domain.Platform.PlatformBillingInvoiceReminder", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ReminderId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_dunning_events_reminder");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingInvoice", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_invoices_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Platform.PlatformBillingOrder", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "OrderId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_platform_billing_invoices_platform_billing_orders_tenant_id~");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingInvoiceReminder", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_platform_billing_invoice_reminders_users_created_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_invoice_reminders_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Platform.PlatformBillingInvoice", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "InvoiceId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_invoice_reminders_platform_billing_invoice~");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingOrder", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_orders_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Platform.PlatformBillingQuote", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "QuoteId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_orders_platform_billing_quotes_tenant_id_q~");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingOrderItem", b =>
                {
                    b.HasOne("Tiku.Domain.Platform.SaasOfferingVersion", null)
                        .WithMany()
                        .HasForeignKey("OfferingVersionId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_order_items_saas_offering_versions_offerin~");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_order_items_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Platform.PlatformBillingOrder", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "OrderId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_order_items_platform_billing_orders_tenant~");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingPayment", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_payments_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Platform.PlatformBillingOrder", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "OrderId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_payments_platform_billing_orders_tenant_id~");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingPaymentEvent", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_payment_events_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Platform.PlatformBillingPayment", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PaymentId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_payment_events_platform_billing_payments_t~");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingQuote", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_quotes_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingQuoteItem", b =>
                {
                    b.HasOne("Tiku.Domain.Platform.SaasOfferingVersion", null)
                        .WithMany()
                        .HasForeignKey("OfferingVersionId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_quote_items_saas_offering_versions_offerin~");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_quote_items_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Platform.PlatformBillingQuote", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "QuoteId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_quote_items_platform_billing_quotes_tenant~");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.PlatformBillingRefund", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_refunds_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Platform.PlatformBillingOrder", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "OrderId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_platform_billing_refunds_platform_billing_orders_tenant_id_~");

                    b.HasOne("Tiku.Domain.Platform.PlatformBillingPayment", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PaymentId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_platform_billing_refunds_platform_billing_payments_tenant_i~");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.SaasFeatureLimitDefinition", b =>
                {
                    b.HasOne("Tiku.Domain.Platform.SaasFeature", null)
                        .WithMany()
                        .HasForeignKey("FeatureCode")
                        .HasPrincipalKey("Code")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_saas_feature_limit_definitions_saas_features_feature_code");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.SaasOfferingVersion", b =>
                {
                    b.HasOne("Tiku.Domain.Platform.SaasOffering", null)
                        .WithMany()
                        .HasForeignKey("OfferingId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_saas_offering_versions_saas_offerings_offering_id");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.SaasOfferingVersionFeature", b =>
                {
                    b.HasOne("Tiku.Domain.Platform.SaasFeature", null)
                        .WithMany()
                        .HasForeignKey("FeatureCode")
                        .HasPrincipalKey("Code")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_saas_offering_version_features_saas_features_feature_code");

                    b.HasOne("Tiku.Domain.Platform.SaasOfferingVersion", null)
                        .WithMany()
                        .HasForeignKey("OfferingVersionId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_saas_offering_version_features_saas_offering_versions_offer~");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.SaasOfferingVersionLimit", b =>
                {
                    b.HasOne("Tiku.Domain.Platform.SaasFeatureLimitDefinition", null)
                        .WithMany()
                        .HasForeignKey("MetricCode")
                        .HasPrincipalKey("MetricCode")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_saas_offering_version_limits_saas_feature_limit_definitions~");

                    b.HasOne("Tiku.Domain.Platform.SaasOfferingVersion", null)
                        .WithMany()
                        .HasForeignKey("OfferingVersionId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_saas_offering_version_limits_saas_offering_versions_offerin~");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.TenantBillingProfile", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithOne()
                        .HasForeignKey("Tiku.Domain.Platform.TenantBillingProfile", "TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_billing_profiles_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.TenantFeatureOverride", b =>
                {
                    b.HasOne("Tiku.Domain.Platform.SaasFeature", null)
                        .WithMany()
                        .HasForeignKey("FeatureCode")
                        .HasPrincipalKey("Code")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_feature_overrides_saas_features_feature_code");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_feature_overrides_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.TenantFeatureUsage", b =>
                {
                    b.HasOne("Tiku.Domain.Platform.SaasFeatureLimitDefinition", null)
                        .WithMany()
                        .HasForeignKey("MetricCode")
                        .HasPrincipalKey("MetricCode")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_feature_usage_saas_feature_limit_definitions_metric_~");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_feature_usage_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.TenantSaasSubscription", b =>
                {
                    b.HasOne("Tiku.Domain.Platform.SaasOfferingVersion", null)
                        .WithMany()
                        .HasForeignKey("BaseOfferingVersionId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_saas_subscriptions_saas_offering_versions_base_offer~");

                    b.HasOne("Tiku.Domain.Platform.SaasOfferingVersion", null)
                        .WithMany()
                        .HasForeignKey("ScheduledBaseOfferingVersionId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_tenant_saas_subscriptions_saas_offering_versions_scheduled_~");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_saas_subscriptions_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Platform.TenantSaasSubscriptionItem", b =>
                {
                    b.HasOne("Tiku.Domain.Platform.SaasOfferingVersion", null)
                        .WithMany()
                        .HasForeignKey("OfferingVersionId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_saas_subscription_items_saas_offering_versions_offer~");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_saas_subscription_items_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Platform.PlatformBillingOrderItem", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SourceOrderItemId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_tenant_saas_subscription_items_platform_billing_order_items~");

                    b.HasOne("Tiku.Domain.Platform.TenantSaasSubscription", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SubscriptionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_saas_subscription_items_tenant_saas_subscriptions_te~");
                });

            modelBuilder.Entity("Tiku.Domain.QuestionBanks.Question", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_questions_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Category", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "CategoryId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_questions_categories_tenant_id_category_id");

                    b.HasOne("Tiku.Domain.Content.ContentNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ContentNodeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_questions_content_nodes_tenant_id_content_node_id");

                    b.HasOne("Tiku.Domain.Content.ContentEntry", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "EntryId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_questions_content_entries_tenant_id_entry_id");

                    b.HasOne("Tiku.Domain.Catalog.ModuleNode", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "NodeId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_questions_module_nodes_tenant_id_node_id");

                    b.HasOne("Tiku.Domain.Content.QuestionCollection", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "PrimaryCollectionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_questions_question_collections_tenant_id_primary_collection~");

                    b.HasOne("Tiku.Domain.QuestionBanks.QuestionBank", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "QuestionBankId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_questions_question_banks_tenant_id_question_bank_id");

                    b.HasOne("Tiku.Domain.Catalog.Subject", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "SubjectId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_questions_subjects_tenant_id_subject_id");

                    b.HasOne("Tiku.Domain.QuestionBanks.QuestionVersion", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "Id", "CurrentVersionId")
                        .HasPrincipalKey("TenantId", "QuestionId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_questions_question_versions_tenant_id_id_current_version_id");
                });

            modelBuilder.Entity("Tiku.Domain.QuestionBanks.QuestionBank", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_question_banks_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_question_banks_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.QuestionBanks.QuestionVersion", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_question_versions_users_created_by");

                    b.HasOne("Tiku.Domain.QuestionBanks.Question", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "QuestionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_question_versions_questions_tenant_id_question_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.AuthChallenge", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_auth_challenges_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_auth_challenges_users_user_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.AuthLoginEvent", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_auth_login_events_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_auth_login_events_users_user_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.AuthSession", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .HasConstraintName("fk_auth_sessions_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_auth_sessions_users_user_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.SmsSendRateLimit", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_sms_send_rate_limits_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.SmsVerificationCode", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_sms_verification_codes_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.Tenant", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("OwnerUserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenants_users_owner_user_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantAuthPolicy", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithOne()
                        .HasForeignKey("Tiku.Domain.Tenancy.TenantAuthPolicy", "TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_auth_policies_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantBranding", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithOne()
                        .HasForeignKey("Tiku.Domain.Tenancy.TenantBranding", "TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_branding_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantClass", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_classes_users_created_by");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_classes_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UpdatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_classes_users_updated_by");

                    b.HasOne("Tiku.Domain.Catalog.Region", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "RegionId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Restrict)
                        .HasConstraintName("fk_tenant_classes_regions_tenant_id_region_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantClassMember", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_class_members_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_class_members_users_user_id");

                    b.HasOne("Tiku.Domain.Tenancy.TenantClass", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ClassId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_class_members_tenant_classes_tenant_id_class_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantDomain", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_domains_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantExternalProvider", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_external_providers_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantFrontendConfig", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_frontend_configs_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantMembership", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_memberships_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_memberships_users_user_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantSecret", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_secrets_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantSettings", b =>
                {
                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithOne()
                        .HasForeignKey("Tiku.Domain.Tenancy.TenantSettings", "TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_settings_tenants_tenant_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantStudentFollowup", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("AssignedToUserId")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_student_followups_users_assigned_to_user_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CompletedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_student_followups_users_completed_by");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("StudentUserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_student_followups_users_student_user_id");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_student_followups_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Tenancy.TenantClass", null)
                        .WithMany()
                        .HasForeignKey("TenantId", "ClassId")
                        .HasPrincipalKey("TenantId", "Id")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_student_followups_tenant_classes_tenant_id_class_id");
                });

            modelBuilder.Entity("Tiku.Domain.Tenancy.TenantStudentNote", b =>
                {
                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("CreatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_student_notes_users_created_by");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("StudentUserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_student_notes_users_student_user_id");

                    b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
                        .WithMany()
                        .HasForeignKey("TenantId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired()
                        .HasConstraintName("fk_tenant_student_notes_tenants_tenant_id");

                    b.HasOne("Tiku.Domain.Identity.User", null)
                        .WithMany()
                        .HasForeignKey("UpdatedBy")
                        .OnDelete(DeleteBehavior.SetNull)
                        .HasConstraintName("fk_tenant_student_notes_users_updated_by");
                });
#pragma warning restore 612, 618
        }
    }
}
