/*
  Warnings:

  - You are about to drop the column `mediaAssets` on the `Dealer` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "Dealer" DROP COLUMN "mediaAssets";

-- CreateTable
CREATE TABLE "MediaAsset" (
    "id" TEXT NOT NULL,
    "dealerId" TEXT NOT NULL,
    "cloudflareId" TEXT NOT NULL,
    "url" TEXT NOT NULL,
    "filename" TEXT NOT NULL,
    "mimeType" TEXT NOT NULL,
    "size" INTEGER NOT NULL,
    "width" INTEGER,
    "height" INTEGER,
    "alt" TEXT,
    "context" TEXT NOT NULL DEFAULT 'general',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "AmsoilImage" (
    "id" TEXT NOT NULL,
    "cloudflareId" TEXT NOT NULL,
    "url" TEXT NOT NULL,
    "filename" TEXT NOT NULL,
    "mimeType" TEXT NOT NULL,
    "size" INTEGER NOT NULL,
    "width" INTEGER,
    "height" INTEGER,
    "name" TEXT NOT NULL,
    "category" TEXT NOT NULL,
    "description" TEXT,
    "tags" TEXT[],
    "sortOrder" INTEGER NOT NULL DEFAULT 0,
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "createdBy" TEXT NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "MediaAsset_cloudflareId_key" ON "MediaAsset"("cloudflareId");

-- CreateIndex
CREATE INDEX "MediaAsset_dealerId_createdAt_idx" ON "MediaAsset"("dealerId", "createdAt");

-- CreateIndex
CREATE UNIQUE INDEX "AmsoilImage_cloudflareId_key" ON "AmsoilImage"("cloudflareId");

-- CreateIndex
CREATE INDEX "AmsoilImage_category_isActive_sortOrder_idx" ON "AmsoilImage"("category", "isActive", "sortOrder");

-- AddForeignKey
ALTER TABLE "MediaAsset" ADD CONSTRAINT "MediaAsset_dealerId_fkey" FOREIGN KEY ("dealerId") REFERENCES "Dealer"("id") ON DELETE CASCADE ON UPDATE CASCADE;
