-- CreateSchema
CREATE SCHEMA IF NOT EXISTS "public";

-- CreateEnum
CREATE TYPE "public"."ChatMessageRole" AS ENUM ('USER', 'ASSISTANT', 'SYSTEM');

-- CreateEnum
CREATE TYPE "public"."PageContentType" AS ENUM ('RICH_TEXT', 'HTML', 'MARKDOWN');

-- CreateEnum
CREATE TYPE "public"."PageStatus" AS ENUM ('DRAFT', 'PUBLISHED', 'ARCHIVED');

-- CreateEnum
CREATE TYPE "public"."DonationStatus" AS ENUM ('PENDING', 'COMPLETED', 'FAILED', 'REFUNDED', 'CANCELLED');

-- CreateEnum
CREATE TYPE "public"."SubscriptionStatus" AS ENUM ('ACTIVE', 'CANCELLED', 'PAST_DUE', 'TRIALING', 'INCOMPLETE', 'INCOMPLETE_EXPIRED', 'UNPAID');

-- CreateEnum
CREATE TYPE "public"."ReadingPlanType" AS ENUM ('PREDEFINED', 'CUSTOM');

-- CreateEnum
CREATE TYPE "public"."ReadingPlanStatus" AS ENUM ('ACTIVE', 'COMPLETED', 'PAUSED', 'CANCELLED');

-- CreateTable
CREATE TABLE "public"."User" (
    "id" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "passwordHash" TEXT NOT NULL,
    "name" TEXT,
    "role" TEXT NOT NULL DEFAULT 'user',
    "theme" TEXT NOT NULL DEFAULT 'light',
    "fontSize" TEXT NOT NULL DEFAULT 'medium',
    "favoriteBibleVersion" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "lastLoginAt" TIMESTAMP(3),
    "subscriptionTier" TEXT NOT NULL DEFAULT 'free',
    "subscriptionStatus" TEXT NOT NULL DEFAULT 'active',
    "conversationLimit" INTEGER NOT NULL DEFAULT 10,
    "conversationCount" INTEGER NOT NULL DEFAULT 0,
    "limitResetDate" TIMESTAMP(3),
    "stripeCustomerId" TEXT,
    "stripeSubscriptionId" TEXT,

    CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."Session" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "token" TEXT NOT NULL,
    "expiresAt" TIMESTAMP(3) NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "Session_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."BibleVersion" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "abbreviation" TEXT NOT NULL,
    "language" TEXT NOT NULL,
    "description" TEXT,
    "country" TEXT,
    "englishTitle" TEXT,
    "flagImageUrl" TEXT,
    "zipFileUrl" TEXT,
    "isDefault" BOOLEAN NOT NULL DEFAULT false,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "BibleVersion_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."BibleBook" (
    "id" TEXT NOT NULL,
    "versionId" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "testament" TEXT NOT NULL,
    "orderNum" INTEGER NOT NULL,
    "bookKey" TEXT NOT NULL,

    CONSTRAINT "BibleBook_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."BibleChapter" (
    "id" TEXT NOT NULL,
    "bookId" TEXT NOT NULL,
    "chapterNum" INTEGER NOT NULL,

    CONSTRAINT "BibleChapter_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."BibleVerse" (
    "id" TEXT NOT NULL,
    "chapterId" TEXT NOT NULL,
    "verseNum" INTEGER NOT NULL,
    "text" TEXT NOT NULL,

    CONSTRAINT "BibleVerse_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."BiblePassage" (
    "id" TEXT NOT NULL,
    "testament" TEXT NOT NULL,
    "book" TEXT NOT NULL,
    "chapter" INTEGER NOT NULL,
    "verse" INTEGER NOT NULL,
    "ref" TEXT NOT NULL,
    "lang" TEXT NOT NULL DEFAULT 'ro',
    "translation" TEXT NOT NULL DEFAULT 'FIDELA',
    "textRaw" TEXT NOT NULL,
    "textNorm" TEXT NOT NULL,
    "embedding" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "BiblePassage_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."ChatConversation" (
    "id" TEXT NOT NULL,
    "userId" TEXT,
    "title" TEXT NOT NULL,
    "language" TEXT NOT NULL,
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "lastMessageAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "ChatConversation_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."ChatMessage" (
    "id" TEXT NOT NULL,
    "conversationId" TEXT NOT NULL,
    "userId" TEXT,
    "role" "public"."ChatMessageRole" NOT NULL,
    "content" TEXT NOT NULL,
    "metadata" JSONB,
    "timestamp" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "ChatMessage_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."Bookmark" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "verseId" TEXT NOT NULL,
    "note" TEXT,
    "color" TEXT NOT NULL DEFAULT '#FFD700',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "Bookmark_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."ChapterBookmark" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "bookId" TEXT NOT NULL,
    "chapterNum" INTEGER NOT NULL,
    "note" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "ChapterBookmark_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."Highlight" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "verseId" TEXT NOT NULL,
    "color" TEXT NOT NULL,
    "note" TEXT,
    "tags" TEXT[] DEFAULT ARRAY[]::TEXT[],
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Highlight_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."UserHighlight" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "verseId" TEXT NOT NULL,
    "color" TEXT NOT NULL DEFAULT 'yellow',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "UserHighlight_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."Note" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "verseId" TEXT NOT NULL,
    "content" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Note_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."PrayerRequest" (
    "id" TEXT NOT NULL,
    "userId" TEXT,
    "title" TEXT NOT NULL,
    "description" TEXT NOT NULL,
    "category" TEXT NOT NULL,
    "author" TEXT NOT NULL,
    "isAnonymous" BOOLEAN NOT NULL DEFAULT false,
    "isPublic" BOOLEAN NOT NULL DEFAULT true,
    "language" TEXT NOT NULL DEFAULT 'en',
    "prayerCount" INTEGER NOT NULL DEFAULT 0,
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "PrayerRequest_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."Prayer" (
    "id" TEXT NOT NULL,
    "requestId" TEXT NOT NULL,
    "ipAddress" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "Prayer_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."UserPrayer" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "requestId" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "UserPrayer_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."ReadingHistory" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "versionId" TEXT NOT NULL,
    "bookId" TEXT NOT NULL,
    "chapterNum" INTEGER NOT NULL,
    "verseNum" INTEGER,
    "viewedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "ReadingHistory_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."UserPreference" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "key" TEXT NOT NULL,
    "value" TEXT NOT NULL,

    CONSTRAINT "UserPreference_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."Page" (
    "id" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "slug" TEXT NOT NULL,
    "content" TEXT NOT NULL,
    "contentType" "public"."PageContentType" NOT NULL DEFAULT 'RICH_TEXT',
    "excerpt" TEXT,
    "featuredImage" TEXT,
    "seoTitle" TEXT,
    "seoDescription" TEXT,
    "status" "public"."PageStatus" NOT NULL DEFAULT 'DRAFT',
    "showInNavigation" BOOLEAN NOT NULL DEFAULT false,
    "showInFooter" BOOLEAN NOT NULL DEFAULT false,
    "navigationOrder" INTEGER,
    "footerOrder" INTEGER,
    "createdBy" TEXT NOT NULL,
    "updatedBy" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "publishedAt" TIMESTAMP(3),

    CONSTRAINT "Page_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."MediaFile" (
    "id" TEXT NOT NULL,
    "filename" TEXT NOT NULL,
    "originalName" TEXT NOT NULL,
    "mimeType" TEXT NOT NULL,
    "size" INTEGER NOT NULL,
    "path" TEXT NOT NULL,
    "url" TEXT NOT NULL,
    "alt" TEXT,
    "uploadedBy" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "MediaFile_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."SocialMediaLink" (
    "id" TEXT NOT NULL,
    "platform" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "url" TEXT NOT NULL,
    "icon" TEXT NOT NULL,
    "isEnabled" BOOLEAN NOT NULL DEFAULT true,
    "order" INTEGER NOT NULL DEFAULT 0,
    "createdBy" TEXT NOT NULL,
    "updatedBy" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "SocialMediaLink_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."MailgunSettings" (
    "id" TEXT NOT NULL,
    "apiKey" TEXT NOT NULL,
    "domain" TEXT NOT NULL,
    "region" TEXT NOT NULL DEFAULT 'US',
    "fromEmail" TEXT NOT NULL,
    "fromName" TEXT NOT NULL,
    "replyToEmail" TEXT,
    "isEnabled" BOOLEAN NOT NULL DEFAULT false,
    "testMode" BOOLEAN NOT NULL DEFAULT true,
    "webhookUrl" TEXT,
    "updatedBy" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "MailgunSettings_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."Donation" (
    "id" TEXT NOT NULL,
    "userId" TEXT,
    "stripeSessionId" TEXT NOT NULL,
    "stripePaymentId" TEXT,
    "email" TEXT NOT NULL,
    "name" TEXT,
    "amount" INTEGER NOT NULL,
    "currency" TEXT NOT NULL DEFAULT 'usd',
    "status" "public"."DonationStatus" NOT NULL DEFAULT 'PENDING',
    "message" TEXT,
    "isAnonymous" BOOLEAN NOT NULL DEFAULT false,
    "isRecurring" BOOLEAN NOT NULL DEFAULT false,
    "recurringInterval" TEXT,
    "metadata" JSONB,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Donation_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."Subscription" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "stripeSubscriptionId" TEXT NOT NULL,
    "stripePriceId" TEXT NOT NULL,
    "stripeCustomerId" TEXT NOT NULL,
    "status" "public"."SubscriptionStatus" NOT NULL,
    "currentPeriodStart" TIMESTAMP(3) NOT NULL,
    "currentPeriodEnd" TIMESTAMP(3) NOT NULL,
    "cancelAtPeriodEnd" BOOLEAN NOT NULL DEFAULT false,
    "tier" TEXT NOT NULL,
    "interval" TEXT NOT NULL,
    "metadata" JSONB,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Subscription_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."ReadingPlan" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "type" "public"."ReadingPlanType" NOT NULL DEFAULT 'PREDEFINED',
    "duration" INTEGER NOT NULL,
    "schedule" JSONB NOT NULL,
    "difficulty" TEXT NOT NULL DEFAULT 'beginner',
    "language" TEXT NOT NULL DEFAULT 'en',
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "ReadingPlan_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."UserReadingPlan" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "planId" TEXT,
    "name" TEXT NOT NULL,
    "startDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "targetEndDate" TIMESTAMP(3) NOT NULL,
    "actualEndDate" TIMESTAMP(3),
    "status" "public"."ReadingPlanStatus" NOT NULL DEFAULT 'ACTIVE',
    "currentDay" INTEGER NOT NULL DEFAULT 1,
    "completedDays" INTEGER NOT NULL DEFAULT 0,
    "streak" INTEGER NOT NULL DEFAULT 0,
    "longestStreak" INTEGER NOT NULL DEFAULT 0,
    "customSchedule" JSONB,
    "reminderEnabled" BOOLEAN NOT NULL DEFAULT true,
    "reminderTime" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "UserReadingPlan_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."UserReadingProgress" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "userPlanId" TEXT NOT NULL,
    "planDay" INTEGER NOT NULL,
    "date" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "bookId" TEXT NOT NULL,
    "chapterNum" INTEGER NOT NULL,
    "versesRead" TEXT,
    "completed" BOOLEAN NOT NULL DEFAULT true,
    "notes" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "UserReadingProgress_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "public"."User"("email");

-- CreateIndex
CREATE UNIQUE INDEX "User_stripeCustomerId_key" ON "public"."User"("stripeCustomerId");

-- CreateIndex
CREATE UNIQUE INDEX "User_stripeSubscriptionId_key" ON "public"."User"("stripeSubscriptionId");

-- CreateIndex
CREATE INDEX "User_role_idx" ON "public"."User"("role");

-- CreateIndex
CREATE INDEX "User_subscriptionTier_idx" ON "public"."User"("subscriptionTier");

-- CreateIndex
CREATE INDEX "User_stripeCustomerId_idx" ON "public"."User"("stripeCustomerId");

-- CreateIndex
CREATE UNIQUE INDEX "Session_token_key" ON "public"."Session"("token");

-- CreateIndex
CREATE INDEX "Session_userId_idx" ON "public"."Session"("userId");

-- CreateIndex
CREATE INDEX "Session_token_idx" ON "public"."Session"("token");

-- CreateIndex
CREATE INDEX "BibleVersion_language_idx" ON "public"."BibleVersion"("language");

-- CreateIndex
CREATE INDEX "BibleVersion_isDefault_idx" ON "public"."BibleVersion"("isDefault");

-- CreateIndex
CREATE INDEX "BibleVersion_language_isDefault_idx" ON "public"."BibleVersion"("language", "isDefault");

-- CreateIndex
CREATE INDEX "BibleVersion_name_idx" ON "public"."BibleVersion"("name");

-- CreateIndex
CREATE INDEX "BibleVersion_abbreviation_idx" ON "public"."BibleVersion"("abbreviation");

-- CreateIndex
CREATE UNIQUE INDEX "BibleVersion_abbreviation_language_key" ON "public"."BibleVersion"("abbreviation", "language");

-- CreateIndex
CREATE INDEX "BibleBook_versionId_idx" ON "public"."BibleBook"("versionId");

-- CreateIndex
CREATE INDEX "BibleBook_testament_idx" ON "public"."BibleBook"("testament");

-- CreateIndex
CREATE UNIQUE INDEX "BibleBook_versionId_orderNum_key" ON "public"."BibleBook"("versionId", "orderNum");

-- CreateIndex
CREATE UNIQUE INDEX "BibleBook_versionId_bookKey_key" ON "public"."BibleBook"("versionId", "bookKey");

-- CreateIndex
CREATE INDEX "BibleChapter_bookId_idx" ON "public"."BibleChapter"("bookId");

-- CreateIndex
CREATE UNIQUE INDEX "BibleChapter_bookId_chapterNum_key" ON "public"."BibleChapter"("bookId", "chapterNum");

-- CreateIndex
CREATE INDEX "BibleVerse_chapterId_idx" ON "public"."BibleVerse"("chapterId");

-- CreateIndex
CREATE UNIQUE INDEX "BibleVerse_chapterId_verseNum_key" ON "public"."BibleVerse"("chapterId", "verseNum");

-- CreateIndex
CREATE INDEX "BiblePassage_book_chapter_idx" ON "public"."BiblePassage"("book", "chapter");

-- CreateIndex
CREATE INDEX "BiblePassage_testament_idx" ON "public"."BiblePassage"("testament");

-- CreateIndex
CREATE UNIQUE INDEX "BiblePassage_translation_lang_book_chapter_verse_key" ON "public"."BiblePassage"("translation", "lang", "book", "chapter", "verse");

-- CreateIndex
CREATE INDEX "ChatConversation_userId_language_lastMessageAt_idx" ON "public"."ChatConversation"("userId", "language", "lastMessageAt");

-- CreateIndex
CREATE INDEX "ChatConversation_isActive_lastMessageAt_idx" ON "public"."ChatConversation"("isActive", "lastMessageAt");

-- CreateIndex
CREATE INDEX "ChatMessage_conversationId_timestamp_idx" ON "public"."ChatMessage"("conversationId", "timestamp");

-- CreateIndex
CREATE INDEX "ChatMessage_userId_timestamp_idx" ON "public"."ChatMessage"("userId", "timestamp");

-- CreateIndex
CREATE INDEX "Bookmark_userId_idx" ON "public"."Bookmark"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "Bookmark_userId_verseId_key" ON "public"."Bookmark"("userId", "verseId");

-- CreateIndex
CREATE INDEX "ChapterBookmark_userId_idx" ON "public"."ChapterBookmark"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "ChapterBookmark_userId_bookId_chapterNum_key" ON "public"."ChapterBookmark"("userId", "bookId", "chapterNum");

-- CreateIndex
CREATE INDEX "Highlight_userId_idx" ON "public"."Highlight"("userId");

-- CreateIndex
CREATE INDEX "Highlight_verseId_idx" ON "public"."Highlight"("verseId");

-- CreateIndex
CREATE UNIQUE INDEX "Highlight_userId_verseId_key" ON "public"."Highlight"("userId", "verseId");

-- CreateIndex
CREATE INDEX "UserHighlight_userId_idx" ON "public"."UserHighlight"("userId");

-- CreateIndex
CREATE INDEX "UserHighlight_verseId_idx" ON "public"."UserHighlight"("verseId");

-- CreateIndex
CREATE UNIQUE INDEX "UserHighlight_userId_verseId_key" ON "public"."UserHighlight"("userId", "verseId");

-- CreateIndex
CREATE INDEX "Note_userId_idx" ON "public"."Note"("userId");

-- CreateIndex
CREATE INDEX "Note_verseId_idx" ON "public"."Note"("verseId");

-- CreateIndex
CREATE INDEX "PrayerRequest_createdAt_idx" ON "public"."PrayerRequest"("createdAt");

-- CreateIndex
CREATE INDEX "PrayerRequest_category_idx" ON "public"."PrayerRequest"("category");

-- CreateIndex
CREATE INDEX "PrayerRequest_isActive_idx" ON "public"."PrayerRequest"("isActive");

-- CreateIndex
CREATE UNIQUE INDEX "Prayer_requestId_ipAddress_key" ON "public"."Prayer"("requestId", "ipAddress");

-- CreateIndex
CREATE INDEX "UserPrayer_userId_idx" ON "public"."UserPrayer"("userId");

-- CreateIndex
CREATE INDEX "UserPrayer_requestId_idx" ON "public"."UserPrayer"("requestId");

-- CreateIndex
CREATE UNIQUE INDEX "UserPrayer_userId_requestId_key" ON "public"."UserPrayer"("userId", "requestId");

-- CreateIndex
CREATE INDEX "ReadingHistory_userId_viewedAt_idx" ON "public"."ReadingHistory"("userId", "viewedAt");

-- CreateIndex
CREATE INDEX "ReadingHistory_userId_versionId_idx" ON "public"."ReadingHistory"("userId", "versionId");

-- CreateIndex
CREATE UNIQUE INDEX "ReadingHistory_userId_versionId_key" ON "public"."ReadingHistory"("userId", "versionId");

-- CreateIndex
CREATE UNIQUE INDEX "UserPreference_userId_key_key" ON "public"."UserPreference"("userId", "key");

-- CreateIndex
CREATE UNIQUE INDEX "Page_slug_key" ON "public"."Page"("slug");

-- CreateIndex
CREATE INDEX "Page_slug_idx" ON "public"."Page"("slug");

-- CreateIndex
CREATE INDEX "Page_status_idx" ON "public"."Page"("status");

-- CreateIndex
CREATE INDEX "Page_showInNavigation_navigationOrder_idx" ON "public"."Page"("showInNavigation", "navigationOrder");

-- CreateIndex
CREATE INDEX "Page_showInFooter_footerOrder_idx" ON "public"."Page"("showInFooter", "footerOrder");

-- CreateIndex
CREATE INDEX "MediaFile_uploadedBy_idx" ON "public"."MediaFile"("uploadedBy");

-- CreateIndex
CREATE INDEX "MediaFile_mimeType_idx" ON "public"."MediaFile"("mimeType");

-- CreateIndex
CREATE INDEX "SocialMediaLink_isEnabled_order_idx" ON "public"."SocialMediaLink"("isEnabled", "order");

-- CreateIndex
CREATE UNIQUE INDEX "SocialMediaLink_platform_key" ON "public"."SocialMediaLink"("platform");

-- CreateIndex
CREATE INDEX "MailgunSettings_isEnabled_idx" ON "public"."MailgunSettings"("isEnabled");

-- CreateIndex
CREATE UNIQUE INDEX "Donation_stripeSessionId_key" ON "public"."Donation"("stripeSessionId");

-- CreateIndex
CREATE INDEX "Donation_userId_idx" ON "public"."Donation"("userId");

-- CreateIndex
CREATE INDEX "Donation_status_idx" ON "public"."Donation"("status");

-- CreateIndex
CREATE INDEX "Donation_createdAt_idx" ON "public"."Donation"("createdAt");

-- CreateIndex
CREATE INDEX "Donation_email_idx" ON "public"."Donation"("email");

-- CreateIndex
CREATE UNIQUE INDEX "Subscription_stripeSubscriptionId_key" ON "public"."Subscription"("stripeSubscriptionId");

-- CreateIndex
CREATE INDEX "Subscription_userId_idx" ON "public"."Subscription"("userId");

-- CreateIndex
CREATE INDEX "Subscription_status_idx" ON "public"."Subscription"("status");

-- CreateIndex
CREATE INDEX "Subscription_stripeSubscriptionId_idx" ON "public"."Subscription"("stripeSubscriptionId");

-- CreateIndex
CREATE INDEX "ReadingPlan_type_idx" ON "public"."ReadingPlan"("type");

-- CreateIndex
CREATE INDEX "ReadingPlan_language_idx" ON "public"."ReadingPlan"("language");

-- CreateIndex
CREATE INDEX "ReadingPlan_isActive_idx" ON "public"."ReadingPlan"("isActive");

-- CreateIndex
CREATE INDEX "UserReadingPlan_userId_idx" ON "public"."UserReadingPlan"("userId");

-- CreateIndex
CREATE INDEX "UserReadingPlan_status_idx" ON "public"."UserReadingPlan"("status");

-- CreateIndex
CREATE INDEX "UserReadingPlan_userId_status_idx" ON "public"."UserReadingPlan"("userId", "status");

-- CreateIndex
CREATE INDEX "UserReadingProgress_userId_idx" ON "public"."UserReadingProgress"("userId");

-- CreateIndex
CREATE INDEX "UserReadingProgress_userPlanId_idx" ON "public"."UserReadingProgress"("userPlanId");

-- CreateIndex
CREATE INDEX "UserReadingProgress_userId_date_idx" ON "public"."UserReadingProgress"("userId", "date");

-- CreateIndex
CREATE UNIQUE INDEX "UserReadingProgress_userPlanId_planDay_bookId_chapterNum_key" ON "public"."UserReadingProgress"("userPlanId", "planDay", "bookId", "chapterNum");

-- AddForeignKey
ALTER TABLE "public"."Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."BibleBook" ADD CONSTRAINT "BibleBook_versionId_fkey" FOREIGN KEY ("versionId") REFERENCES "public"."BibleVersion"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."BibleChapter" ADD CONSTRAINT "BibleChapter_bookId_fkey" FOREIGN KEY ("bookId") REFERENCES "public"."BibleBook"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."BibleVerse" ADD CONSTRAINT "BibleVerse_chapterId_fkey" FOREIGN KEY ("chapterId") REFERENCES "public"."BibleChapter"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."ChatConversation" ADD CONSTRAINT "ChatConversation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."ChatMessage" ADD CONSTRAINT "ChatMessage_conversationId_fkey" FOREIGN KEY ("conversationId") REFERENCES "public"."ChatConversation"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."ChatMessage" ADD CONSTRAINT "ChatMessage_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."Bookmark" ADD CONSTRAINT "Bookmark_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."Bookmark" ADD CONSTRAINT "Bookmark_verseId_fkey" FOREIGN KEY ("verseId") REFERENCES "public"."BibleVerse"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."ChapterBookmark" ADD CONSTRAINT "ChapterBookmark_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."ChapterBookmark" ADD CONSTRAINT "ChapterBookmark_bookId_fkey" FOREIGN KEY ("bookId") REFERENCES "public"."BibleBook"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."Highlight" ADD CONSTRAINT "Highlight_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."Highlight" ADD CONSTRAINT "Highlight_verseId_fkey" FOREIGN KEY ("verseId") REFERENCES "public"."BibleVerse"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."UserHighlight" ADD CONSTRAINT "UserHighlight_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."Note" ADD CONSTRAINT "Note_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."Note" ADD CONSTRAINT "Note_verseId_fkey" FOREIGN KEY ("verseId") REFERENCES "public"."BibleVerse"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."PrayerRequest" ADD CONSTRAINT "PrayerRequest_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."Prayer" ADD CONSTRAINT "Prayer_requestId_fkey" FOREIGN KEY ("requestId") REFERENCES "public"."PrayerRequest"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."UserPrayer" ADD CONSTRAINT "UserPrayer_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."UserPrayer" ADD CONSTRAINT "UserPrayer_requestId_fkey" FOREIGN KEY ("requestId") REFERENCES "public"."PrayerRequest"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."ReadingHistory" ADD CONSTRAINT "ReadingHistory_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."UserPreference" ADD CONSTRAINT "UserPreference_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."Page" ADD CONSTRAINT "Page_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "public"."User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."Page" ADD CONSTRAINT "Page_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "public"."User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."MediaFile" ADD CONSTRAINT "MediaFile_uploadedBy_fkey" FOREIGN KEY ("uploadedBy") REFERENCES "public"."User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."SocialMediaLink" ADD CONSTRAINT "SocialMediaLink_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "public"."User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."SocialMediaLink" ADD CONSTRAINT "SocialMediaLink_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "public"."User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."MailgunSettings" ADD CONSTRAINT "MailgunSettings_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "public"."User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."Donation" ADD CONSTRAINT "Donation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."Subscription" ADD CONSTRAINT "Subscription_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."UserReadingPlan" ADD CONSTRAINT "UserReadingPlan_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."UserReadingPlan" ADD CONSTRAINT "UserReadingPlan_planId_fkey" FOREIGN KEY ("planId") REFERENCES "public"."ReadingPlan"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."UserReadingProgress" ADD CONSTRAINT "UserReadingProgress_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."UserReadingProgress" ADD CONSTRAINT "UserReadingProgress_userPlanId_fkey" FOREIGN KEY ("userPlanId") REFERENCES "public"."UserReadingPlan"("id") ON DELETE CASCADE ON UPDATE CASCADE;

