-- Hotfix for: errno 150 "Foreign key constraint is incorrectly formed" on topup_requests.
-- Safe to run manually in phpMyAdmin if the main bot still shows the old fatal error after upload.

CREATE TABLE IF NOT EXISTS topup_requests (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  user_id BIGINT UNSIGNED NOT NULL,
  transaction_id BIGINT UNSIGNED NULL,
  amount BIGINT NOT NULL,
  method ENUM('card_to_card') NOT NULL DEFAULT 'card_to_card',
  receipt_type VARCHAR(30) NULL,
  receipt_file_id VARCHAR(255) NULL,
  receipt_caption TEXT NULL,
  status ENUM('pending','approved','rejected') NOT NULL DEFAULT 'pending',
  admin_user_id BIGINT UNSIGNED NULL,
  reject_reason TEXT NULL,
  created_at DATETIME NOT NULL,
  updated_at DATETIME NULL,
  INDEX idx_topup_user(user_id),
  INDEX idx_topup_status(status),
  INDEX idx_topup_created(created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
