-- Simplified migration script for wallet top-up
-- This version skips operations that have already been applied

-- 1. Add wallet_topup to paymentType ENUM (only if not already present)
-- Note: If this fails, the ENUM might already include wallet_topup - that's okay

-- Check and modify paymentType ENUM
ALTER TABLE `payments` 
MODIFY COLUMN `paymentType` ENUM('unlock_supplier', 'order_payment', 'delivery', 'workshop_installation', 'internal_procurement', 'wallet_topup') NOT NULL;

-- 2. Make inquiryId nullable in payments table
ALTER TABLE `payments` 
MODIFY COLUMN `inquiryId` INT NULL;

-- 3. Make inquiryId and supplierId nullable in receipts table
ALTER TABLE `receipts` 
MODIFY COLUMN `inquiryId` INT NULL,
MODIFY COLUMN `supplierId` INT NULL;

-- 4. Make receiptPhoto nullable in receipts table
ALTER TABLE `receipts` 
MODIFY COLUMN `receiptPhoto` VARCHAR(500) NULL;

-- 5. Add receiptType column (skip this line if you get "Duplicate column" error)
-- ALTER TABLE `receipts` 
-- ADD COLUMN `receiptType` ENUM('purchase', 'topup') DEFAULT 'purchase' AFTER `supplierId`;

