-- CreateTable
CREATE TABLE "CommissionCustomCard" (
    "id" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "sortIndex" INTEGER NOT NULL DEFAULT 0,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "referenceImageUrl" TEXT,
    "isVisible" BOOLEAN NOT NULL DEFAULT true,
    "isSpecialOffer" BOOLEAN NOT NULL DEFAULT false,

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

-- CreateTable
CREATE TABLE "CommissionCustomCardOption" (
    "id" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "sortIndex" INTEGER NOT NULL DEFAULT 0,
    "cardId" TEXT NOT NULL,
    "optionId" TEXT NOT NULL,
    "priceRange" TEXT,
    "pricePercent" DOUBLE PRECISION,
    "price" DOUBLE PRECISION,

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

-- CreateTable
CREATE TABLE "CommissionCustomCardExtra" (
    "id" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "sortIndex" INTEGER NOT NULL DEFAULT 0,
    "cardId" TEXT NOT NULL,
    "extraId" TEXT NOT NULL,
    "priceRange" TEXT,
    "pricePercent" DOUBLE PRECISION,
    "price" DOUBLE PRECISION,

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

-- CreateIndex
CREATE INDEX "CommissionCustomCard_isVisible_sortIndex_idx" ON "CommissionCustomCard"("isVisible", "sortIndex");

-- CreateIndex
CREATE UNIQUE INDEX "CommissionCustomCardOption_cardId_optionId_key" ON "CommissionCustomCardOption"("cardId", "optionId");

-- CreateIndex
CREATE UNIQUE INDEX "CommissionCustomCardExtra_cardId_extraId_key" ON "CommissionCustomCardExtra"("cardId", "extraId");

-- AddForeignKey
ALTER TABLE "CommissionCustomCardOption" ADD CONSTRAINT "CommissionCustomCardOption_cardId_fkey" FOREIGN KEY ("cardId") REFERENCES "CommissionCustomCard"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CommissionCustomCardOption" ADD CONSTRAINT "CommissionCustomCardOption_optionId_fkey" FOREIGN KEY ("optionId") REFERENCES "CommissionOption"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CommissionCustomCardExtra" ADD CONSTRAINT "CommissionCustomCardExtra_cardId_fkey" FOREIGN KEY ("cardId") REFERENCES "CommissionCustomCard"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CommissionCustomCardExtra" ADD CONSTRAINT "CommissionCustomCardExtra_extraId_fkey" FOREIGN KEY ("extraId") REFERENCES "CommissionExtra"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
