-- CreateTable
CREATE TABLE "VideoWatchSegment" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "videoId" TEXT NOT NULL,
    "startSec" INTEGER NOT NULL,
    "endSec" INTEGER NOT NULL,
    "watchedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE INDEX "VideoWatchSegment_userId_videoId_idx" ON "VideoWatchSegment"("userId", "videoId");

-- CreateIndex
CREATE INDEX "VideoWatchSegment_watchedAt_idx" ON "VideoWatchSegment"("watchedAt");

-- CreateIndex
CREATE INDEX "VideoWatchSegment_userId_idx" ON "VideoWatchSegment"("userId");

-- CreateIndex
CREATE INDEX "VideoWatchSegment_videoId_idx" ON "VideoWatchSegment"("videoId");

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

-- AddForeignKey
ALTER TABLE "VideoWatchSegment" ADD CONSTRAINT "VideoWatchSegment_videoId_fkey" FOREIGN KEY ("videoId") REFERENCES "Video"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "VideoWatchSegment" ADD CONSTRAINT "VideoWatchSegment_userId_videoId_fkey" FOREIGN KEY ("userId", "videoId") REFERENCES "VideoProgress"("userId", "videoId") ON DELETE CASCADE ON UPDATE CASCADE;
