/*
  Warnings:

  - You are about to drop the column `artistName` on the `Tattoo` table. All the data in the column will be lost.
  - You are about to drop the column `studioName` on the `Tattoo` table. All the data in the column will be lost.
  - The `bodyPlacement` column on the `Tattoo` table would be dropped and recreated. This will lead to data loss if there is data in the column.
  - The `status` column on the `Tattoo` table would be dropped and recreated. This will lead to data loss if there is data in the column.
  - Added the required column `updatedAt` to the `TattooMemoryMedia` table without a default value. This is not possible if the table is not empty.
  - Added the required column `updatedAt` to the `TattooScanHistory` table without a default value. This is not possible if the table is not empty.

*/
-- CreateEnum
CREATE TYPE "TattooStatus" AS ENUM ('ACTIVE', 'ARCHIVED', 'DELETED');

-- CreateEnum
CREATE TYPE "BodyPlacement" AS ENUM ('HEAD', 'FACE', 'NECK', 'CHEST', 'BACK', 'LEFT_ARM', 'RIGHT_ARM', 'LEFT_LEG', 'RIGHT_LEG', 'HAND', 'FOOT', 'OTHER');

-- AlterTable
ALTER TABLE "Tattoo" DROP COLUMN "artistName",
DROP COLUMN "studioName",
ADD COLUMN     "commentCount" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN     "isMemory" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN     "isPost" BOOLEAN NOT NULL DEFAULT true,
ADD COLUMN     "isScanned" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN     "likeCount" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN     "scanCount" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN     "shareCount" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN     "viewCount" INTEGER NOT NULL DEFAULT 0,
DROP COLUMN "bodyPlacement",
ADD COLUMN     "bodyPlacement" "BodyPlacement",
DROP COLUMN "status",
ADD COLUMN     "status" "TattooStatus" NOT NULL DEFAULT 'ACTIVE';

-- AlterTable
ALTER TABLE "TattooMedia" ADD COLUMN     "displayOrder" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN     "isCover" BOOLEAN NOT NULL DEFAULT false;

-- AlterTable
ALTER TABLE "TattooMemory" ADD COLUMN     "latitude" DOUBLE PRECISION,
ADD COLUMN     "location" TEXT,
ADD COLUMN     "longitude" DOUBLE PRECISION,
ADD COLUMN     "privacy" "TattooPrivacyType" NOT NULL DEFAULT 'PRIVATE';

-- AlterTable
ALTER TABLE "TattooMemoryMedia" ADD COLUMN     "fileSize" INTEGER,
ADD COLUMN     "updatedAt" TIMESTAMP(3) NOT NULL;

-- AlterTable
ALTER TABLE "TattooScanHistory" ADD COLUMN     "deviceType" TEXT,
ADD COLUMN     "ipAddress" TEXT,
ADD COLUMN     "platform" TEXT,
ADD COLUMN     "scanImageUrl" TEXT,
ADD COLUMN     "updatedAt" TIMESTAMP(3) NOT NULL;

-- CreateTable
CREATE TABLE "TattooTag" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "TattooTagAssignment" (
    "id" SERIAL NOT NULL,
    "tattooId" INTEGER NOT NULL,
    "tagId" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "Review" (
    "id" SERIAL NOT NULL,
    "userId" INTEGER NOT NULL,
    "tattooId" INTEGER,
    "rating" INTEGER NOT NULL,
    "review" TEXT,
    "artistReply" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "ReviewMedia" (
    "id" SERIAL NOT NULL,
    "reviewId" INTEGER NOT NULL,
    "fileUrl" VARCHAR(1024) NOT NULL,
    "thumbnailUrl" VARCHAR(1024),
    "mimeType" VARCHAR(100),
    "fileSize" INTEGER,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE UNIQUE INDEX "TattooTag_name_key" ON "TattooTag"("name");

-- CreateIndex
CREATE UNIQUE INDEX "TattooTagAssignment_tattooId_tagId_key" ON "TattooTagAssignment"("tattooId", "tagId");

-- CreateIndex
CREATE INDEX "Review_userId_idx" ON "Review"("userId");

-- CreateIndex
CREATE INDEX "Review_tattooId_idx" ON "Review"("tattooId");

-- CreateIndex
CREATE UNIQUE INDEX "Review_userId_tattooId_key" ON "Review"("userId", "tattooId");

-- CreateIndex
CREATE INDEX "Tattoo_userId_idx" ON "Tattoo"("userId");

-- CreateIndex
CREATE INDEX "Tattoo_categoryId_idx" ON "Tattoo"("categoryId");

-- CreateIndex
CREATE INDEX "Tattoo_styleId_idx" ON "Tattoo"("styleId");

-- CreateIndex
CREATE INDEX "Tattoo_privacy_idx" ON "Tattoo"("privacy");

-- CreateIndex
CREATE INDEX "Tattoo_status_idx" ON "Tattoo"("status");

-- CreateIndex
CREATE INDEX "TattooMedia_tattooId_idx" ON "TattooMedia"("tattooId");

-- AddForeignKey
ALTER TABLE "TattooTagAssignment" ADD CONSTRAINT "TattooTagAssignment_tattooId_fkey" FOREIGN KEY ("tattooId") REFERENCES "Tattoo"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TattooTagAssignment" ADD CONSTRAINT "TattooTagAssignment_tagId_fkey" FOREIGN KEY ("tagId") REFERENCES "TattooTag"("id") ON DELETE CASCADE ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "Review" ADD CONSTRAINT "Review_tattooId_fkey" FOREIGN KEY ("tattooId") REFERENCES "Tattoo"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ReviewMedia" ADD CONSTRAINT "ReviewMedia_reviewId_fkey" FOREIGN KEY ("reviewId") REFERENCES "Review"("id") ON DELETE CASCADE ON UPDATE CASCADE;
