-- CreateEnum
CREATE TYPE "public"."AIChatTypes" AS ENUM ('SUPPORTIVE', 'ANAYLTICS', 'MOTIVATIONAL', 'GIRLFRIEND', 'BOYFRIEND');

-- CreateEnum
CREATE TYPE "public"."ActionTypes" AS ENUM ('CHAT', 'LOGIN', 'LOGOUT', 'SIGNUP', 'CONTACT_SUPPORT');

-- CreateEnum
CREATE TYPE "public"."ContentTypes" AS ENUM ('KEY_BENEFITS', 'PLATEFORM_HIGHLIGHTS', 'HOWITWoRKS', 'PROCESS_SIMPLIFIED', 'FREQUENTLY_ASKED_QUESTION', 'ADVANCED_EMOTIONAL');

-- CreateEnum
CREATE TYPE "public"."MessageType" AS ENUM ('ME', 'AI');

-- CreateEnum
CREATE TYPE "public"."OTP_FOR" AS ENUM ('VERIFICATION', 'FORGET_PASSWORD', 'REGISTRATION');

-- CreateEnum
CREATE TYPE "public"."Role" AS ENUM ('USER', 'ADMIN');

-- CreateEnum
CREATE TYPE "public"."TierTypeProps" AS ENUM ('FREE_TIER', 'HEALING', 'THERAPY');

-- CreateTable
CREATE TABLE "public"."AIChatRoom" (
    "id" TEXT NOT NULL,
    "chatType" "public"."AIChatTypes" NOT NULL DEFAULT 'SUPPORTIVE',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "chatCount" INTEGER NOT NULL DEFAULT 0,
    "userId" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "public"."AIChatRoomMessaages" (
    "id" TEXT NOT NULL,
    "message" TEXT NOT NULL,
    "messageType" "public"."MessageType" NOT NULL DEFAULT 'AI',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "userId" TEXT NOT NULL,
    "chatRoom" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "public"."Admin" (
    "id" TEXT NOT NULL,
    "full_name" TEXT,
    "email" TEXT NOT NULL,
    "password" TEXT NOT NULL,
    "two_factor_enabled" BOOLEAN NOT NULL DEFAULT false,
    "two_factor_secret" TEXT,
    "last_login" TIMESTAMP(3),
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "public"."ContactSuport" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "subject" TEXT NOT NULL,
    "message" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "userId" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "public"."Content" (
    "id" TEXT NOT NULL,
    "contentType" "public"."ContentTypes" NOT NULL DEFAULT 'KEY_BENEFITS',
    "ContentTitle" TEXT,
    "ContentImage" TEXT,
    "ContentDescription" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "public"."FileUpload" (
    "id" TEXT NOT NULL,
    "file" TEXT,
    "fileType" TEXT,

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

-- CreateTable
CREATE TABLE "public"."NewsLetter" (
    "id" TEXT NOT NULL,
    "name" TEXT,
    "email" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "public"."Otp" (
    "id" TEXT NOT NULL,
    "code" TEXT NOT NULL,
    "is_used" BOOLEAN NOT NULL DEFAULT false,
    "for" "public"."OTP_FOR" NOT NULL DEFAULT 'VERIFICATION',
    "expire_at" TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE "public"."RecentActions" (
    "id" TEXT NOT NULL,
    "email" TEXT,
    "action" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "actionType" "public"."ActionTypes" NOT NULL DEFAULT 'LOGIN',
    "userId" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "public"."Session" (
    "id" TEXT NOT NULL,
    "token" TEXT,
    "expiresAt" TIMESTAMP(3) NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "userId" TEXT NOT NULL,
    "browser" TEXT,
    "deviceType" TEXT,
    "ip" TEXT,
    "isRevoked" BOOLEAN NOT NULL DEFAULT false,
    "platform" TEXT,
    "userAgent" TEXT,

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

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

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

-- CreateTable
CREATE TABLE "public"."Testimonial" (
    "id" TEXT NOT NULL,
    "testimonial" TEXT NOT NULL,
    "testinomailAuthor" TEXT NOT NULL,
    "testimonialType" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "public"."users" (
    "id" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "password" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "image_id" TEXT,
    "is_active" BOOLEAN NOT NULL DEFAULT true,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "is_profile_completed" BOOLEAN NOT NULL DEFAULT false,
    "notification_on" BOOLEAN NOT NULL DEFAULT true,
    "otp_id" TEXT,
    "user_type" "public"."Role" NOT NULL DEFAULT 'USER',
    "isSubscribe" BOOLEAN NOT NULL DEFAULT false,
    "is_verified" BOOLEAN NOT NULL DEFAULT false,
    "full_name" TEXT,

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

-- CreateIndex
CREATE INDEX "AIChatRoom_chatType_idx" ON "public"."AIChatRoom"("chatType");

-- CreateIndex
CREATE INDEX "AIChatRoom_createdAt_idx" ON "public"."AIChatRoom"("createdAt");

-- CreateIndex
CREATE INDEX "AIChatRoomMessaages_createdAt_idx" ON "public"."AIChatRoomMessaages"("createdAt");

-- CreateIndex
CREATE INDEX "AIChatRoomMessaages_message_idx" ON "public"."AIChatRoomMessaages"("message");

-- CreateIndex
CREATE UNIQUE INDEX "Admin_email_key" ON "public"."Admin"("email");

-- CreateIndex
CREATE INDEX "ContactSuport_createdAt_idx" ON "public"."ContactSuport"("createdAt");

-- CreateIndex
CREATE INDEX "ContactSuport_email_idx" ON "public"."ContactSuport"("email");

-- CreateIndex
CREATE INDEX "ContactSuport_name_idx" ON "public"."ContactSuport"("name");

-- CreateIndex
CREATE INDEX "Content_ContentTitle_idx" ON "public"."Content"("ContentTitle");

-- CreateIndex
CREATE INDEX "Content_contentType_idx" ON "public"."Content"("contentType");

-- CreateIndex
CREATE INDEX "NewsLetter_createdAt_idx" ON "public"."NewsLetter"("createdAt");

-- CreateIndex
CREATE INDEX "NewsLetter_email_idx" ON "public"."NewsLetter"("email");

-- CreateIndex
CREATE INDEX "NewsLetter_name_idx" ON "public"."NewsLetter"("name");

-- CreateIndex
CREATE UNIQUE INDEX "Otp_code_key" ON "public"."Otp"("code");

-- CreateIndex
CREATE INDEX "RecentActions_email_idx" ON "public"."RecentActions"("email");

-- CreateIndex
CREATE UNIQUE INDEX "Session_expiresAt_key" ON "public"."Session"("expiresAt");

-- CreateIndex
CREATE INDEX "Session_id_idx" ON "public"."Session"("id");

-- CreateIndex
CREATE INDEX "Subscriptions_createdAt_idx" ON "public"."Subscriptions"("createdAt");

-- CreateIndex
CREATE INDEX "Subscriptions_subscriptionId_idx" ON "public"."Subscriptions"("subscriptionId");

-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "public"."users"("email");

-- CreateIndex
CREATE UNIQUE INDEX "users_image_id_key" ON "public"."users"("image_id");

-- CreateIndex
CREATE UNIQUE INDEX "users_otp_id_key" ON "public"."users"("otp_id");

-- CreateIndex
CREATE INDEX "users_createdAt_idx" ON "public"."users"("createdAt");

-- CreateIndex
CREATE INDEX "users_email_idx" ON "public"."users"("email");

-- AddForeignKey
ALTER TABLE "public"."AIChatRoom" ADD CONSTRAINT "AIChatRoom_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."AIChatRoomMessaages" ADD CONSTRAINT "AIChatRoomMessaages_chatRoom_fkey" FOREIGN KEY ("chatRoom") REFERENCES "public"."AIChatRoom"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."AIChatRoomMessaages" ADD CONSTRAINT "AIChatRoomMessaages_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."ContactSuport" ADD CONSTRAINT "ContactSuport_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."RecentActions" ADD CONSTRAINT "RecentActions_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "public"."Subscriptions" ADD CONSTRAINT "Subscriptions_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."users" ADD CONSTRAINT "users_image_id_fkey" FOREIGN KEY ("image_id") REFERENCES "public"."FileUpload"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."users" ADD CONSTRAINT "users_otp_id_fkey" FOREIGN KEY ("otp_id") REFERENCES "public"."Otp"("id") ON DELETE SET NULL ON UPDATE CASCADE;
