-- Create notification_settings table for global notification service configuration
-- This allows switching between OneSignal, Firebase, or both

CREATE TABLE IF NOT EXISTS notification_settings (
  id INT PRIMARY KEY AUTO_INCREMENT,
  setting_key VARCHAR(100) UNIQUE NOT NULL,
  setting_value TEXT,
  description VARCHAR(500),
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_setting_key (setting_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Insert default notification service settings
INSERT INTO notification_settings (setting_key, setting_value, description) VALUES
  ('notification_service_enabled', 'true', 'Master switch for all notification services'),
  ('onesignal_enabled', 'true', 'Enable/disable OneSignal service'),
  ('firebase_enabled', 'false', 'Enable/disable Firebase Cloud Messaging service'),
  ('primary_service', 'onesignal', 'Primary notification service (onesignal, firebase, or both)'),
  ('fallback_enabled', 'true', 'Enable fallback to secondary service if primary fails'),
  ('onesignal_priority', '1', 'Priority order for OneSignal (1=highest)'),
  ('firebase_priority', '2', 'Priority order for Firebase (1=highest)'),
  ('notification_retry_limit', '3', 'Maximum retry attempts for failed notifications'),
  ('notification_timeout_ms', '30000', 'Timeout for notification requests in milliseconds')
ON DUPLICATE KEY UPDATE 
  setting_value = VALUES(setting_value),
  description = VALUES(description);
