-- CreateTable
CREATE TABLE "user" (
    "id" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "Guild" (
    "id" TEXT NOT NULL,
    "guild_id" TEXT NOT NULL,
    "auto_roles" TEXT[],
    "report_channel" TEXT,

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

-- CreateTable
CREATE TABLE "guild_welcome_message" (
    "id" TEXT NOT NULL,
    "guild_id" TEXT NOT NULL,
    "channel_id" TEXT NOT NULL,
    "title" TEXT NOT NULL DEFAULT '🎉 Welcome to the server {user}!',
    "description" TEXT NOT NULL DEFAULT '> Welcome to **{guild}** We hope you enjoy your stay here!',
    "embed_color" TEXT NOT NULL DEFAULT '#5865F2',
    "enabled" BOOLEAN NOT NULL DEFAULT false,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "guild_leave_message" (
    "id" TEXT NOT NULL,
    "guild_id" TEXT NOT NULL,
    "channel_id" TEXT NOT NULL,
    "title" TEXT NOT NULL DEFAULT '👋 Goodbye {user}!',
    "description" TEXT NOT NULL DEFAULT '> We''re sorry to see you go!',
    "embed_color" TEXT NOT NULL DEFAULT '#5865F2',
    "enabled" BOOLEAN NOT NULL DEFAULT false,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "Tag" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "content" TEXT NOT NULL,
    "usages" INTEGER NOT NULL DEFAULT 0,
    "image" TEXT,
    "ownerId" TEXT NOT NULL,
    "guildId" TEXT NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "Guild_guild_id_key" ON "Guild"("guild_id");

-- CreateIndex
CREATE UNIQUE INDEX "guild_welcome_message_guild_id_key" ON "guild_welcome_message"("guild_id");

-- CreateIndex
CREATE UNIQUE INDEX "guild_leave_message_guild_id_key" ON "guild_leave_message"("guild_id");

-- AddForeignKey
ALTER TABLE "guild_welcome_message" ADD CONSTRAINT "guild_welcome_message_guild_id_fkey" FOREIGN KEY ("guild_id") REFERENCES "Guild"("guild_id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "guild_leave_message" ADD CONSTRAINT "guild_leave_message_guild_id_fkey" FOREIGN KEY ("guild_id") REFERENCES "Guild"("guild_id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Tag" ADD CONSTRAINT "Tag_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Tag" ADD CONSTRAINT "Tag_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
