-- AlterTable
ALTER TABLE "GuildSettings" ADD COLUMN "snipeEnabled" BOOLEAN NOT NULL DEFAULT false;

-- AlterTable
ALTER TABLE "LoggingConfig" ADD COLUMN "retentionDays" INTEGER NOT NULL DEFAULT 90;

-- CreateTable
CREATE TABLE "PremiumTierConfig" (
    "tier" TEXT NOT NULL,
    "maxTags" INTEGER NOT NULL,
    "maxFeeds" INTEGER NOT NULL,
    "maxBackups" INTEGER NOT NULL,
    "features" JSONB NOT NULL,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "PremiumTierConfig_pkey" PRIMARY KEY ("tier")
);

-- CreateTable
CREATE TABLE "GuildPremiumAssignment" (
    "id" TEXT NOT NULL,
    "guildId" TEXT NOT NULL,
    "tier" TEXT NOT NULL,
    "note" TEXT,
    "assignedById" TEXT NOT NULL,
    "expiresAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "UserPremiumAssignment" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "tier" TEXT NOT NULL,
    "note" TEXT,
    "assignedById" TEXT NOT NULL,
    "expiresAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "GdprDeletionLog" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "guildId" TEXT,
    "summary" JSONB,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE UNIQUE INDEX "GuildPremiumAssignment_guildId_key" ON "GuildPremiumAssignment"("guildId");

-- CreateIndex
CREATE INDEX "GuildPremiumAssignment_tier_idx" ON "GuildPremiumAssignment"("tier");

-- CreateIndex
CREATE UNIQUE INDEX "UserPremiumAssignment_userId_key" ON "UserPremiumAssignment"("userId");

-- CreateIndex
CREATE INDEX "UserPremiumAssignment_tier_idx" ON "UserPremiumAssignment"("tier");

-- CreateIndex
CREATE INDEX "GdprDeletionLog_userId_createdAt_idx" ON "GdprDeletionLog"("userId", "createdAt");

-- Seed default tier configs
INSERT INTO "PremiumTierConfig" ("tier", "maxTags", "maxFeeds", "maxBackups", "features", "updatedAt")
VALUES
  (
    'FREE',
    15,
    3,
    2,
    '{"tags":true,"feeds":true,"guildbackup":true}'::jsonb,
    CURRENT_TIMESTAMP
  ),
  (
    'PREMIUM',
    100,
    25,
    25,
    '{"tags":true,"feeds":true,"guildbackup":true}'::jsonb,
    CURRENT_TIMESTAMP
  );
