-- CreateEnum
CREATE TYPE "ReviewSource" AS ENUM ('CASHI', 'GOOGLE');

-- CreateEnum
CREATE TYPE "ReviewGoogleStatus" AS ENUM ('NOT_POSTED', 'POSTED', 'REMOVED');

-- AlterTable
ALTER TABLE "shops" ADD COLUMN     "googleApiKey" TEXT,
ADD COLUMN     "googlePlaceId" TEXT,
ADD COLUMN     "instagramAccessToken" TEXT,
ADD COLUMN     "instagramBusinessAccountId" TEXT;

-- CreateTable
CREATE TABLE "reviews" (
    "id" TEXT NOT NULL,
    "shopId" TEXT NOT NULL,
    "source" "ReviewSource" NOT NULL DEFAULT 'CASHI',
    "customerName" TEXT NOT NULL,
    "customerPhone" TEXT,
    "rating" INTEGER NOT NULL,
    "comment" TEXT NOT NULL,
    "googleStatus" "ReviewGoogleStatus" NOT NULL DEFAULT 'NOT_POSTED',
    "googleExternalId" TEXT,
    "googlePostDate" TIMESTAMP(3),
    "response" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE INDEX "reviews_shopId_createdAt_idx" ON "reviews"("shopId", "createdAt");

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