-- CreateEnum
CREATE TYPE "ClientTimelineContentType" AS ENUM ('CALENDAR_EVENT', 'DOCUMENT', 'RECOMMENDATION');

-- CreateTable
CREATE TABLE "ClientTimelineEntry" (
    "id" TEXT NOT NULL,
    "teamId" TEXT NOT NULL,
    "contactId" TEXT NOT NULL,
    "contentType" "ClientTimelineContentType" NOT NULL,
    "contentId" TEXT NOT NULL,
    "datetime" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE INDEX "ClientTimelineEntry_teamId_contactId_datetime_idx" ON "ClientTimelineEntry"("teamId", "contactId", "datetime");

-- CreateIndex
CREATE INDEX "ClientTimelineEntry_contactId_datetime_idx" ON "ClientTimelineEntry"("contactId", "datetime");

-- CreateIndex
CREATE UNIQUE INDEX "ClientTimelineEntry_teamId_contentType_contentId_key" ON "ClientTimelineEntry"("teamId", "contentType", "contentId");

-- AddForeignKey
ALTER TABLE "ClientTimelineEntry" ADD CONSTRAINT "ClientTimelineEntry_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ClientTimelineEntry" ADD CONSTRAINT "ClientTimelineEntry_contactId_fkey" FOREIGN KEY ("contactId") REFERENCES "Contact"("id") ON DELETE CASCADE ON UPDATE CASCADE;

