-- CreateEnum
CREATE TYPE "SupportMessageDirection" AS ENUM ('USER_TO_ADMIN', 'ADMIN_TO_USER');

-- AlterEnum
ALTER TYPE "TelegramSessionStep" ADD VALUE 'WAITING_SUPPORT_MESSAGE';

-- CreateTable
CREATE TABLE "SupportMessage" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "direction" "SupportMessageDirection" NOT NULL,
    "content" TEXT NOT NULL,
    "telegramFileId" TEXT,
    "adminTelegramId" TEXT,
    "forwardedMessageId" INTEGER,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE INDEX "SupportMessage_userId_idx" ON "SupportMessage"("userId");

-- CreateIndex
CREATE INDEX "SupportMessage_adminTelegramId_forwardedMessageId_idx" ON "SupportMessage"("adminTelegramId", "forwardedMessageId");

-- AddForeignKey
ALTER TABLE "SupportMessage" ADD CONSTRAINT "SupportMessage_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
