-- Migration: add withdrawal_otps and discount_tiers
--
-- Both tables were already in schema.prisma but were never captured in a
-- migration file. Without this migration, prisma migrate deploy on a fresh
-- database would not create them, breaking the two-step wallet withdrawal
-- flow (routes/wallet.js POST /withdraw needs WithdrawalOtp) and the loyalty
-- discount tier admin flow.

-- CreateTable
CREATE TABLE `withdrawal_otps` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `walletId` VARCHAR(191) NOT NULL,
    `amount` DECIMAL(10, 2) NOT NULL,
    `paymentMethod` VARCHAR(191) NOT NULL,
    `accountDetails` TEXT NOT NULL,
    `walletType` VARCHAR(191) NOT NULL DEFAULT 'AUTHOR',
    `codeHash` VARCHAR(191) NOT NULL,
    `expiresAt` DATETIME(3) NOT NULL,
    `consumedAt` DATETIME(3) NULL,
    `failedAttempts` INTEGER NOT NULL DEFAULT 0,
    `ipAddress` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `withdrawal_otps_userId_idx`(`userId`),
    INDEX `withdrawal_otps_expiresAt_idx`(`expiresAt`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `discount_tiers` (
    `id` VARCHAR(191) NOT NULL,
    `name` VARCHAR(191) NOT NULL,
    `description` TEXT NULL,
    `minOrderCount` INTEGER NOT NULL,
    `discountPercent` DOUBLE NOT NULL,
    `isActive` BOOLEAN NOT NULL DEFAULT true,
    `createdBy` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `discount_tiers_isActive_idx`(`isActive`),
    INDEX `discount_tiers_minOrderCount_idx`(`minOrderCount`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `withdrawal_otps` ADD CONSTRAINT `withdrawal_otps_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
