-- MarzPay gateway columns on deposits (idempotent)

SET @col := (SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'deposits' AND COLUMN_NAME = 'payment_gateway');
SET @sql := IF(@col = 0, 'ALTER TABLE deposits ADD COLUMN payment_gateway VARCHAR(20) NULL DEFAULT NULL AFTER status', 'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;

SET @col := (SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'deposits' AND COLUMN_NAME = 'gateway_tx_uuid');
SET @sql := IF(@col = 0, 'ALTER TABLE deposits ADD COLUMN gateway_tx_uuid VARCHAR(64) NULL AFTER payment_gateway', 'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;

SET @col := (SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'deposits' AND COLUMN_NAME = 'gateway_status');
SET @sql := IF(@col = 0, 'ALTER TABLE deposits ADD COLUMN gateway_status VARCHAR(32) NULL AFTER gateway_tx_uuid', 'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;

SET @col := (SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'deposits' AND COLUMN_NAME = 'gateway_provider_tx_id');
SET @sql := IF(@col = 0, 'ALTER TABLE deposits ADD COLUMN gateway_provider_tx_id VARCHAR(64) NULL AFTER gateway_status', 'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;

INSERT IGNORE INTO settings (setting_key, setting_value) VALUES
('marzpay_enabled', '0'),
('marzpay_api_key', ''),
('marzpay_api_secret', '');
