/*
  Warnings:

  - You are about to drop the column `dob` on the `UserProfile` table. All the data in the column will be lost.
  - You are about to drop the column `guardianActive` on the `UserProfile` table. All the data in the column will be lost.
  - You are about to drop the column `guardianName` on the `UserProfile` table. All the data in the column will be lost.
  - You are about to drop the column `notificationStatus` on the `UserProfile` table. All the data in the column will be lost.
  - You are about to drop the column `postalCode` on the `UserProfile` table. All the data in the column will be lost.
  - You are about to drop the column `preferences` on the `UserProfile` table. All the data in the column will be lost.
  - You are about to drop the column `profileImageUrl` on the `UserProfile` table. All the data in the column will be lost.

*/
-- CreateEnum
CREATE TYPE "TattooPrivacyType" AS ENUM ('PRIVATE', 'TATTOO_ONLY', 'TATTOO_MEMORY', 'TATTOO_MEMORY_METADATA');

-- DropForeignKey
ALTER TABLE "UserProfile" DROP CONSTRAINT "UserProfile_userId_fkey";

-- AlterTable
ALTER TABLE "User" ADD COLUMN     "userProfileId" INTEGER;

-- AlterTable
ALTER TABLE "UserAuth" ADD COLUMN     "acceptedTerms" BOOLEAN NOT NULL DEFAULT false;

-- AlterTable
ALTER TABLE "UserProfile" DROP COLUMN "dob",
DROP COLUMN "guardianActive",
DROP COLUMN "guardianName",
DROP COLUMN "notificationStatus",
DROP COLUMN "postalCode",
DROP COLUMN "preferences",
DROP COLUMN "profileImageUrl",
ADD COLUMN     "bio" TEXT,
ADD COLUMN     "city" TEXT,
ADD COLUMN     "experience" INTEGER,
ADD COLUMN     "facebook" TEXT,
ADD COLUMN     "instagram" TEXT,
ADD COLUMN     "isVerified" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN     "latitude" DOUBLE PRECISION,
ADD COLUMN     "longitude" DOUBLE PRECISION,
ADD COLUMN     "state" TEXT,
ADD COLUMN     "studioName" TEXT,
ADD COLUMN     "website" TEXT,
ALTER COLUMN "firstName" SET DATA TYPE TEXT,
ALTER COLUMN "lastName" SET DATA TYPE TEXT,
ALTER COLUMN "country" SET DATA TYPE TEXT,
ALTER COLUMN "mobile" SET DATA TYPE TEXT;

-- CreateTable
CREATE TABLE "ArtistSpeciality" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "ArtistSpecialityAssignment" (
    "id" SERIAL NOT NULL,
    "artistId" INTEGER NOT NULL,
    "specialityId" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "ArtistPortfolio" (
    "id" SERIAL NOT NULL,
    "artistId" INTEGER NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT,
    "isPublic" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "PortfolioStyle" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "ArtistPortfolioStyle" (
    "id" SERIAL NOT NULL,
    "portfolioId" INTEGER NOT NULL,
    "styleId" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "ArtistPortfolioMedia" (
    "id" SERIAL NOT NULL,
    "portfolioId" INTEGER NOT NULL,
    "fileUrl" TEXT NOT NULL,
    "thumbnailUrl" TEXT,
    "mimeType" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "TattooCategory" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "Tattoo" (
    "id" SERIAL NOT NULL,
    "uuid" VARCHAR(36),
    "userId" INTEGER NOT NULL,
    "categoryId" INTEGER,
    "styleId" INTEGER,
    "title" VARCHAR(255),
    "description" TEXT,
    "bodyPlacement" VARCHAR(100),
    "tattooDate" TIMESTAMP(3),
    "artistName" VARCHAR(255),
    "studioName" VARCHAR(255),
    "latitude" DOUBLE PRECISION,
    "longitude" DOUBLE PRECISION,
    "status" TEXT NOT NULL DEFAULT 'active',
    "privacy" "TattooPrivacyType" NOT NULL DEFAULT 'PRIVATE',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "deletedAt" TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE "TattooStyle" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

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

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

-- CreateTable
CREATE TABLE "TattooMemory" (
    "id" SERIAL NOT NULL,
    "tattooId" INTEGER NOT NULL,
    "title" VARCHAR(255),
    "story" TEXT,
    "memoryDate" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

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

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

-- CreateTable
CREATE TABLE "TattooScanHistory" (
    "id" SERIAL NOT NULL,
    "tattooId" INTEGER NOT NULL,
    "userId" INTEGER NOT NULL,
    "latitude" DOUBLE PRECISION,
    "longitude" DOUBLE PRECISION,
    "deviceInfo" JSONB,
    "similarityScore" DOUBLE PRECISION,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE UNIQUE INDEX "ArtistSpeciality_name_key" ON "ArtistSpeciality"("name");

-- CreateIndex
CREATE UNIQUE INDEX "ArtistSpecialityAssignment_artistId_specialityId_key" ON "ArtistSpecialityAssignment"("artistId", "specialityId");

-- CreateIndex
CREATE UNIQUE INDEX "PortfolioStyle_name_key" ON "PortfolioStyle"("name");

-- CreateIndex
CREATE INDEX "ArtistPortfolioStyle_portfolioId_idx" ON "ArtistPortfolioStyle"("portfolioId");

-- CreateIndex
CREATE INDEX "ArtistPortfolioStyle_styleId_idx" ON "ArtistPortfolioStyle"("styleId");

-- CreateIndex
CREATE UNIQUE INDEX "ArtistPortfolioStyle_portfolioId_styleId_key" ON "ArtistPortfolioStyle"("portfolioId", "styleId");

-- CreateIndex
CREATE UNIQUE INDEX "TattooCategory_name_key" ON "TattooCategory"("name");

-- CreateIndex
CREATE UNIQUE INDEX "Tattoo_uuid_key" ON "Tattoo"("uuid");

-- CreateIndex
CREATE UNIQUE INDEX "TattooStyle_name_key" ON "TattooStyle"("name");

-- AddForeignKey
ALTER TABLE "User" ADD CONSTRAINT "User_userProfileId_fkey" FOREIGN KEY ("userProfileId") REFERENCES "UserProfile"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ArtistSpecialityAssignment" ADD CONSTRAINT "ArtistSpecialityAssignment_artistId_fkey" FOREIGN KEY ("artistId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ArtistSpecialityAssignment" ADD CONSTRAINT "ArtistSpecialityAssignment_specialityId_fkey" FOREIGN KEY ("specialityId") REFERENCES "ArtistSpeciality"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ArtistPortfolio" ADD CONSTRAINT "ArtistPortfolio_artistId_fkey" FOREIGN KEY ("artistId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ArtistPortfolioStyle" ADD CONSTRAINT "ArtistPortfolioStyle_portfolioId_fkey" FOREIGN KEY ("portfolioId") REFERENCES "ArtistPortfolio"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ArtistPortfolioStyle" ADD CONSTRAINT "ArtistPortfolioStyle_styleId_fkey" FOREIGN KEY ("styleId") REFERENCES "PortfolioStyle"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ArtistPortfolioMedia" ADD CONSTRAINT "ArtistPortfolioMedia_portfolioId_fkey" FOREIGN KEY ("portfolioId") REFERENCES "ArtistPortfolio"("id") ON DELETE CASCADE ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "Tattoo" ADD CONSTRAINT "Tattoo_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "TattooCategory"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Tattoo" ADD CONSTRAINT "Tattoo_styleId_fkey" FOREIGN KEY ("styleId") REFERENCES "TattooStyle"("id") ON DELETE SET NULL ON UPDATE CASCADE;

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

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

-- AddForeignKey
ALTER TABLE "TattooMemoryMedia" ADD CONSTRAINT "TattooMemoryMedia_memoryId_fkey" FOREIGN KEY ("memoryId") REFERENCES "TattooMemory"("id") ON DELETE CASCADE ON UPDATE CASCADE;

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

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