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

-- CreateTable
CREATE TABLE "loyalty_programs" (
    "id" TEXT NOT NULL,
    "shopId" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "type" "LoyaltyProgramType" NOT NULL,
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "percentageRate" DOUBLE PRECISION,
    "stepAmount" INTEGER,
    "pointsPerStep" INTEGER,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE INDEX "loyalty_programs_shopId_createdAt_idx" ON "loyalty_programs"("shopId", "createdAt");

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