/*
  Warnings:

  - You are about to drop the column `isTemporaryPassword` on the `user` table. All the data in the column will be lost.
  - You are about to drop the column `passwordChangeRequired` on the `user` table. All the data in the column will be lost.
  - A unique constraint covering the columns `[verificationToken]` on the table `user` will be added. If there are existing duplicate values, this will fail.
  - A unique constraint covering the columns `[resetPasswordToken]` on the table `user` will be added. If there are existing duplicate values, this will fail.

*/
-- AlterTable
ALTER TABLE `category` MODIFY `updatedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3);

-- AlterTable
ALTER TABLE `product` MODIFY `description` TEXT NOT NULL,
    MODIFY `updatedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3);

-- AlterTable
ALTER TABLE `scriptversion` MODIFY `releaseNotes` TEXT NULL;

-- AlterTable
ALTER TABLE `subscription` MODIFY `updatedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3);

-- AlterTable
ALTER TABLE `user` DROP COLUMN `isTemporaryPassword`,
    DROP COLUMN `passwordChangeRequired`,
    ADD COLUMN `isVerified` BOOLEAN NOT NULL DEFAULT false,
    ADD COLUMN `resetPasswordExpires` DATETIME(3) NULL,
    ADD COLUMN `resetPasswordToken` VARCHAR(191) NULL,
    ADD COLUMN `verificationExpires` DATETIME(3) NULL,
    ADD COLUMN `verificationToken` VARCHAR(191) NULL,
    MODIFY `twoFactorBackupCodes` LONGTEXT NULL,
    MODIFY `updatedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3);

-- CreateTable
CREATE TABLE `report` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `reporterName` VARCHAR(191) NOT NULL,
    `playerName` VARCHAR(191) NOT NULL,
    `discordUserId` VARCHAR(191) NOT NULL,
    `subject` VARCHAR(191) NOT NULL,
    `description` TEXT NOT NULL,
    `priority` VARCHAR(191) NOT NULL DEFAULT 'Medium',
    `status` VARCHAR(191) NOT NULL DEFAULT 'Open',
    `attachments` LONGTEXT NULL,
    `linkedReports` 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_report_created`(`createdAt`),
    INDEX `idx_report_status`(`status`),
    INDEX `idx_report_priority`(`priority`),
    INDEX `idx_report_player`(`playerName`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateIndex
CREATE INDEX `idx_product_created` ON `product`(`createdAt`);

-- CreateIndex
CREATE INDEX `idx_product_featured` ON `product`(`isFeatured`);

-- CreateIndex
CREATE INDEX `idx_product_status` ON `product`(`status`);

-- CreateIndex
CREATE INDEX `idx_purchase_created` ON `purchase`(`createdAt`);

-- CreateIndex
CREATE INDEX `idx_purchase_type` ON `purchase`(`type`);

-- CreateIndex
CREATE UNIQUE INDEX `User_verificationToken_key` ON `user`(`verificationToken`);

-- CreateIndex
CREATE UNIQUE INDEX `User_resetPasswordToken_key` ON `user`(`resetPasswordToken`);

-- CreateIndex
CREATE INDEX `idx_user_created` ON `user`(`createdAt`);

-- CreateIndex
CREATE INDEX `idx_user_email` ON `user`(`email`);

-- CreateIndex
CREATE INDEX `idx_user_role` ON `user`(`role`);

-- CreateIndex
CREATE INDEX `idx_user_username` ON `user`(`username`);

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