-- CreateEnum
CREATE TYPE "LoyaltyEarnType" AS ENUM ('PERCENTAGE', 'INCREMENTAL');

-- CreateTable
CREATE TABLE "loyalty_settings" (
    "id" TEXT NOT NULL,
    "shopId" TEXT NOT NULL,
    "minOrderFirstPoint" INTEGER NOT NULL,
    "minOrderApplyPoint" INTEGER NOT NULL,
    "validityMonths" INTEGER NOT NULL,
    "maxEarnablePoints" INTEGER NOT NULL,
    "maxRedeemPercent" INTEGER NOT NULL,
    "earnType" "LoyaltyEarnType" NOT NULL,
    "percentageRate" DOUBLE PRECISION,
    "stepAmount" INTEGER,
    "pointsPerStep" INTEGER,
    "welcomeBonus" INTEGER NOT NULL,
    "referralBonus" INTEGER NOT NULL,
    "upiId" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "loyalty_settings_shopId_key" ON "loyalty_settings"("shopId");

-- AddForeignKey
ALTER TABLE "loyalty_settings" ADD CONSTRAINT "loyalty_settings_shopId_fkey" FOREIGN KEY ("shopId") REFERENCES "shops"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
