-- CreateTable
CREATE TABLE "DealerLink" (
    "id" TEXT NOT NULL,
    "dealerId" TEXT NOT NULL,
    "label" VARCHAR(50) NOT NULL,
    "linkType" VARCHAR(20) NOT NULL,
    "pageId" TEXT,
    "externalUrl" VARCHAR(500),
    "openInNewTab" BOOLEAN NOT NULL DEFAULT true,
    "sortOrder" INTEGER NOT NULL DEFAULT 0,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE INDEX "DealerLink_dealerId_sortOrder_idx" ON "DealerLink"("dealerId", "sortOrder");

-- AddForeignKey
ALTER TABLE "DealerLink" ADD CONSTRAINT "DealerLink_dealerId_fkey" FOREIGN KEY ("dealerId") REFERENCES "Dealer"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "DealerLink" ADD CONSTRAINT "DealerLink_pageId_fkey" FOREIGN KEY ("pageId") REFERENCES "Page"("id") ON DELETE SET NULL ON UPDATE CASCADE;
