-- CreateEnum
CREATE TYPE "SubscriptionTier" AS ENUM ('FREE', 'STANDARD', 'PRO', 'PREMIUM');

-- CreateEnum
CREATE TYPE "DeleteCondition" AS ENUM ('OWNER_LEAVE', 'EMPTY');

-- CreateTable
CREATE TABLE "GuildConfig" (
    "guildId" TEXT NOT NULL,
    "prefix" TEXT NOT NULL DEFAULT '!',
    "mimicEnabled" BOOLEAN NOT NULL DEFAULT true,
    "locale" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "GuildConfig_pkey" PRIMARY KEY ("guildId")
);

-- CreateTable
CREATE TABLE "InviteRole" (
    "id" TEXT NOT NULL,
    "guildId" TEXT NOT NULL,
    "inviteCode" TEXT NOT NULL,
    "roleId" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "UserSubscription" (
    "userId" TEXT NOT NULL,
    "tier" "SubscriptionTier" NOT NULL DEFAULT 'FREE',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "UserSubscription_pkey" PRIMARY KEY ("userId")
);

-- CreateTable
CREATE TABLE "GuildOwnership" (
    "guildId" TEXT NOT NULL,
    "ownerId" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "GuildOwnership_pkey" PRIMARY KEY ("guildId")
);

-- CreateTable
CREATE TABLE "VoiceGenerator" (
    "channelId" TEXT NOT NULL,
    "guildId" TEXT NOT NULL,
    "categoryId" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "VoiceGenerator_pkey" PRIMARY KEY ("channelId")
);

-- CreateTable
CREATE TABLE "TempVoiceChannel" (
    "channelId" TEXT NOT NULL,
    "guildId" TEXT NOT NULL,
    "ownerId" TEXT NOT NULL,
    "deleteWhen" "DeleteCondition" NOT NULL DEFAULT 'EMPTY',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "TempVoiceChannel_pkey" PRIMARY KEY ("channelId")
);

-- CreateTable
CREATE TABLE "UserVoiceProfile" (
    "userId" TEXT NOT NULL,
    "customName" TEXT,
    "userLimit" INTEGER,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "UserVoiceProfile_pkey" PRIMARY KEY ("userId")
);

-- CreateTable
CREATE TABLE "UserLocale" (
    "userId" TEXT NOT NULL,
    "locale" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "UserLocale_pkey" PRIMARY KEY ("userId")
);

-- CreateIndex
CREATE UNIQUE INDEX "InviteRole_guildId_inviteCode_key" ON "InviteRole"("guildId", "inviteCode");

-- CreateIndex
CREATE INDEX "GuildOwnership_ownerId_idx" ON "GuildOwnership"("ownerId");

-- CreateIndex
CREATE INDEX "VoiceGenerator_guildId_idx" ON "VoiceGenerator"("guildId");

-- CreateIndex
CREATE INDEX "TempVoiceChannel_guildId_idx" ON "TempVoiceChannel"("guildId");

-- CreateIndex
CREATE INDEX "TempVoiceChannel_ownerId_idx" ON "TempVoiceChannel"("ownerId");

-- AddForeignKey
ALTER TABLE "GuildOwnership" ADD CONSTRAINT "GuildOwnership_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "UserSubscription"("userId") ON DELETE CASCADE ON UPDATE CASCADE;
