-- CreateEnum
CREATE TYPE "DealNoticeSeverity" AS ENUM ('INFO', 'WARNING', 'DANGER', 'SUCCESS');

-- CreateTable
CREATE TABLE "DealNotice" (
    "id" SERIAL NOT NULL,
    "dealId" INTEGER NOT NULL,
    "title" TEXT NOT NULL,
    "body" TEXT,
    "severity" "DealNoticeSeverity" NOT NULL DEFAULT 'INFO',
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "createdBy" INTEGER NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE INDEX "DealNotice_dealId_isActive_createdAt_idx" ON "DealNotice"("dealId", "isActive", "createdAt");

-- CreateIndex
CREATE INDEX "DealNotice_createdBy_idx" ON "DealNotice"("createdBy");

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

-- AddForeignKey
ALTER TABLE "DealNotice" ADD CONSTRAINT "DealNotice_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
