-- Gateway Transactions Table
-- This table logs all interactions with payment gateways

CREATE TABLE IF NOT EXISTS gateway_transactions (
    id INT AUTO_INCREMENT PRIMARY KEY,
    withdrawal_id INT NOT NULL,
    withdrawal_type ENUM('usdt', 'legacy') NOT NULL DEFAULT 'usdt',
    action VARCHAR(50) NOT NULL COMMENT 'withdrawal, status_check, etc.',
    request_data JSON COMMENT 'Data sent to gateway',
    response_data JSON COMMENT 'Response from gateway',
    status ENUM('pending', 'success', 'failed') DEFAULT 'pending',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    
    INDEX idx_withdrawal_id (withdrawal_id),
    INDEX idx_withdrawal_type (withdrawal_type),
    INDEX idx_action (action),
    INDEX idx_status (status),
    INDEX idx_created_at (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
