/*
  Warnings:

  - You are about to drop the column `phone` on the `Gym` table. All the data in the column will be lost.
  - The values [GOPAY,OVO,DANA,CASH] on the enum `Payment_method` will be removed. If these variants are still used in the database, this will fail.
  - The values [OTHER] on the enum `Profile_gender` will be removed. If these variants are still used in the database, this will fail.
  - A unique constraint covering the columns `[name]` on the table `Gym` will be added. If there are existing duplicate values, this will fail.
  - Made the column `gymId` on table `Order` required. This step will fail if there are existing NULL values in that column.

*/
-- DropForeignKey
ALTER TABLE `Order` DROP FOREIGN KEY `Order_gymId_fkey`;

-- DropIndex
DROP INDEX `Order_gymId_fkey` ON `Order`;

-- AlterTable
ALTER TABLE `Gym` DROP COLUMN `phone`,
    MODIFY `isActive` BOOLEAN NOT NULL DEFAULT false;

-- AlterTable
ALTER TABLE `Order` MODIFY `gymId` INTEGER NOT NULL;

-- AlterTable
ALTER TABLE `Payment` ADD COLUMN `proofImageUrl` VARCHAR(191) NULL,
    MODIFY `method` ENUM('BANK_TRANSFER', 'QRIS') NOT NULL;

-- AlterTable
ALTER TABLE `Profile` MODIFY `gender` ENUM('MALE', 'FEMALE') NOT NULL;

-- CreateTable
CREATE TABLE `PaymentApproval` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `paymentId` INTEGER NOT NULL,
    `approvedBy` VARCHAR(191) NOT NULL,
    `approvedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `note` VARCHAR(191) NULL,

    UNIQUE INDEX `PaymentApproval_paymentId_key`(`paymentId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `PaymentRejection` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `paymentId` INTEGER NOT NULL,
    `rejectedBy` VARCHAR(191) NOT NULL,
    `rejectedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `reason` VARCHAR(191) NOT NULL,

    UNIQUE INDEX `PaymentRejection_paymentId_key`(`paymentId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateIndex
CREATE UNIQUE INDEX `Gym_name_key` ON `Gym`(`name`);

-- AddForeignKey
ALTER TABLE `Order` ADD CONSTRAINT `Order_gymId_fkey` FOREIGN KEY (`gymId`) REFERENCES `Gym`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `PaymentApproval` ADD CONSTRAINT `PaymentApproval_paymentId_fkey` FOREIGN KEY (`paymentId`) REFERENCES `Payment`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `PaymentApproval` ADD CONSTRAINT `PaymentApproval_approvedBy_fkey` FOREIGN KEY (`approvedBy`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `PaymentRejection` ADD CONSTRAINT `PaymentRejection_paymentId_fkey` FOREIGN KEY (`paymentId`) REFERENCES `Payment`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `PaymentRejection` ADD CONSTRAINT `PaymentRejection_rejectedBy_fkey` FOREIGN KEY (`rejectedBy`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
