-- CreateEnum
CREATE TYPE "DealAiIssueType" AS ENUM ('NONE', 'PROFANITY', 'PHONE_NUMBER', 'PERSONAL_DATA', 'SPAM', 'OTHER');

-- CreateTable
CREATE TABLE "DealAiReview" (
    "id" SERIAL NOT NULL,
    "dealId" INTEGER NOT NULL,
    "bestCategoryId" INTEGER NOT NULL,
    "needsReview" BOOLEAN NOT NULL DEFAULT false,
    "hasIssue" BOOLEAN NOT NULL DEFAULT false,
    "issueType" "DealAiIssueType" NOT NULL DEFAULT 'NONE',
    "issueReason" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "DealAiReview_dealId_key" ON "DealAiReview"("dealId");

-- CreateIndex
CREATE INDEX "DealAiReview_needsReview_hasIssue_updatedAt_idx" ON "DealAiReview"("needsReview", "hasIssue", "updatedAt");

-- AddForeignKey
ALTER TABLE "DealAiReview" ADD CONSTRAINT "DealAiReview_dealId_fkey" FOREIGN KEY ("dealId") REFERENCES "Deal"("id") ON DELETE CASCADE ON UPDATE CASCADE;
