-- CreateEnum
CREATE TYPE "TakeQuality" AS ENUM ('HERO', 'GOOD', 'PRINT', 'NO_GOOD', 'FALSE_START');

-- CreateEnum
CREATE TYPE "AttachmentFileType" AS ENUM ('IMAGE', 'VIDEO', 'HDRI', 'LIDAR', 'LENS_GRID', 'PDF', 'OTHER');

-- CreateEnum
CREATE TYPE "AttachmentCategory" AS ENUM ('SLATE', 'CAMERA_POSITION', 'WIDE_REFERENCE', 'LENS', 'LIGHTING', 'HDRI', 'TRACKING', 'TEXTURE', 'WITNESS', 'MISCELLANEOUS');

-- CreateTable
CREATE TABLE "shoot_days" (
    "id" TEXT NOT NULL,
    "projectId" TEXT NOT NULL,
    "date" TIMESTAMP(3) NOT NULL,
    "unit" TEXT NOT NULL DEFAULT 'A',
    "label" TEXT,
    "notes" TEXT,
    "createdById" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "setups" (
    "id" TEXT NOT NULL,
    "shootDayId" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "sortOrder" INTEGER NOT NULL DEFAULT 0,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "takes" (
    "id" TEXT NOT NULL,
    "setupId" TEXT NOT NULL,
    "takeNumber" INTEGER NOT NULL,
    "pipelineShotId" TEXT,
    "scene" TEXT,
    "shotLabel" TEXT,
    "unitLabel" TEXT,
    "cameraLetter" TEXT,
    "clipName" TEXT,
    "roll" TEXT,
    "cameraModel" TEXT,
    "resolution" TEXT,
    "codec" TEXT,
    "fps" DOUBLE PRECISION,
    "shutter" TEXT,
    "iso" INTEGER,
    "whiteBalance" INTEGER,
    "colourSpace" TEXT,
    "lensSet" TEXT,
    "lens" TEXT,
    "tStop" TEXT,
    "filters" TEXT,
    "isAnamorphic" BOOLEAN NOT NULL DEFAULT false,
    "hasHdri" BOOLEAN NOT NULL DEFAULT false,
    "hasChromeBall" BOOLEAN NOT NULL DEFAULT false,
    "hasGreyBall" BOOLEAN NOT NULL DEFAULT false,
    "hasMacbeth" BOOLEAN NOT NULL DEFAULT false,
    "hasCleanPlate" BOOLEAN NOT NULL DEFAULT false,
    "hasSurvey" BOOLEAN NOT NULL DEFAULT false,
    "hasLidar" BOOLEAN NOT NULL DEFAULT false,
    "hasWitnessCamera" BOOLEAN NOT NULL DEFAULT false,
    "hasLensGrid" BOOLEAN NOT NULL DEFAULT false,
    "hasTexturePhotos" BOOLEAN NOT NULL DEFAULT false,
    "hasPhotogrammetry" BOOLEAN NOT NULL DEFAULT false,
    "weather" TEXT,
    "sunDirection" TEXT,
    "artificialLights" TEXT,
    "supervisorNotes" TEXT,
    "continuityNotes" TEXT,
    "vfxRequirements" TEXT,
    "quality" "TakeQuality" NOT NULL DEFAULT 'PRINT',
    "createdById" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "take_attachments" (
    "id" TEXT NOT NULL,
    "takeId" TEXT NOT NULL,
    "fileUrl" TEXT NOT NULL,
    "fileKey" TEXT NOT NULL DEFAULT '',
    "fileName" TEXT NOT NULL,
    "fileSize" BIGINT,
    "fileType" "AttachmentFileType" NOT NULL DEFAULT 'IMAGE',
    "category" "AttachmentCategory" NOT NULL DEFAULT 'MISCELLANEOUS',
    "caption" TEXT,
    "sortOrder" INTEGER NOT NULL DEFAULT 0,
    "uploadedById" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE UNIQUE INDEX "takes_setupId_takeNumber_key" ON "takes"("setupId", "takeNumber");

-- AddForeignKey
ALTER TABLE "shoot_days" ADD CONSTRAINT "shoot_days_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "projects"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "shoot_days" ADD CONSTRAINT "shoot_days_createdById_fkey" FOREIGN KEY ("createdById") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "setups" ADD CONSTRAINT "setups_shootDayId_fkey" FOREIGN KEY ("shootDayId") REFERENCES "shoot_days"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "takes" ADD CONSTRAINT "takes_setupId_fkey" FOREIGN KEY ("setupId") REFERENCES "setups"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "takes" ADD CONSTRAINT "takes_pipelineShotId_fkey" FOREIGN KEY ("pipelineShotId") REFERENCES "shots"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "takes" ADD CONSTRAINT "takes_createdById_fkey" FOREIGN KEY ("createdById") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "take_attachments" ADD CONSTRAINT "take_attachments_takeId_fkey" FOREIGN KEY ("takeId") REFERENCES "takes"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "take_attachments" ADD CONSTRAINT "take_attachments_uploadedById_fkey" FOREIGN KEY ("uploadedById") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
