-- Migration: Create system_settings table for superadmin configuration
-- Run this SQL script in your database to create the system settings table

CREATE TABLE IF NOT EXISTS `system_settings` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `setting_key` VARCHAR(100) NOT NULL UNIQUE,
  `setting_value` TEXT,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `setting_key` (`setting_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Insert default Paystack settings (empty values)
INSERT IGNORE INTO `system_settings` (`setting_key`, `setting_value`) VALUES
('paystack_test_public_key', ''),
('paystack_test_secret_key', ''),
('paystack_test_callback_url', ''),
('paystack_test_webhook_url', ''),
('paystack_live_public_key', ''),
('paystack_live_secret_key', ''),
('paystack_live_callback_url', ''),
('paystack_live_webhook_url', ''),
('paystack_environment', 'test'),
('paystack_currency', 'NGN');

-- Add indexes for better performance
CREATE INDEX IF NOT EXISTS `idx_system_settings_key` ON `system_settings` (`setting_key`);
CREATE INDEX IF NOT EXISTS `idx_system_settings_updated` ON `system_settings` (`updated_at`);
