-- CreateTable
CREATE TABLE `discordBot` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(191) NOT NULL,
    `token` TEXT NOT NULL,
    `clientId` VARCHAR(191) NOT NULL,
    `guildId` VARCHAR(191) NULL,
    `isActive` BOOLEAN NOT NULL DEFAULT true,
    `webhookUrl` TEXT NULL,
    `description` TEXT NULL,
    `features` TEXT NULL,
    `createdBy` INTEGER NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `idx_bot_created`(`createdAt`),
    INDEX `idx_bot_active`(`isActive`),
    INDEX `idx_bot_client`(`clientId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateIndex
CREATE INDEX `idx_form_bot` ON `whitelistForm`(`linkedBotId`);

-- AddForeignKey
ALTER TABLE `whitelistForm` ADD CONSTRAINT `whitelistForm_linkedBotId_fkey` FOREIGN KEY (`linkedBotId`) REFERENCES `discordBot`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `discordBot` ADD CONSTRAINT `discordBot_createdBy_fkey` FOREIGN KEY (`createdBy`) REFERENCES `user`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
