-- Migration: Create payment_methods table
-- Description: Stores configuration for all payment methods (Kuda, Opay, Moniepoint, etc.)
-- Date: 2026-02-20

CREATE TABLE IF NOT EXISTS payment_methods (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  code VARCHAR(50) NOT NULL UNIQUE,
  type ENUM('bank_transfer', 'virtual_account', 'mobile_money', 'crypto', 'ussd', 'api') NOT NULL,
  logo_url VARCHAR(255),
  description TEXT,

  -- Fee Configuration
  transaction_fee_percentage DECIMAL(5, 2) DEFAULT 0 COMMENT 'Percentage fee (e.g., 0.50 for 0.5%)',
  transaction_fee_fixed DECIMAL(10, 2) DEFAULT 0 COMMENT 'Fixed fee amount (e.g., 10.00 for ₦10)',
  transaction_fee_cap DECIMAL(10, 2) COMMENT 'Maximum fee cap (e.g., 100.00 for ₦100 max)',

  -- Amount Limits
  min_amount DECIMAL(10, 2) DEFAULT 100 COMMENT 'Minimum deposit ₦100',
  max_amount DECIMAL(10, 2) DEFAULT 500000 COMMENT 'Maximum deposit ₦500,000',

  -- Status and Configuration
  is_active BOOLEAN DEFAULT TRUE,
  is_automated BOOLEAN DEFAULT FALSE COMMENT 'TRUE for API-based, FALSE for manual',
  requires_proof BOOLEAN DEFAULT FALSE COMMENT 'TRUE if payment proof/receipt required',
  processing_time_minutes INT DEFAULT 0 COMMENT '0 = instant, >0 = manual processing time',

  -- API Configuration (stored as JSON)
  config JSON COMMENT 'API keys, credentials, webhook secrets, etc.',

  -- User Instructions
  instructions TEXT COMMENT 'Display instructions for users',

  -- Display Order
  display_order INT DEFAULT 0,

  -- Timestamps
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

  -- Indexes
  INDEX idx_is_active_display_order (is_active, display_order),
  INDEX idx_code (code),
  INDEX idx_type (type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
