-- Setup AWS SES SMTP Configuration in Database
-- This script configures the notification_delivery_config table with AWS SES settings

-- Insert or update AWS SES configuration for email channel
INSERT INTO notification_delivery_config
(channel_type, is_enabled, provider, provider_config, status, success_rate, created_by, updated_by, created_at, updated_at)
VALUES (
  'email',
  true,
  'AWS SES',
  JSON_OBJECT(
    'host', 'email-smtp.us-east-1.amazonaws.com',
    'port', 587,
    'secure', false,
    'user', 'YOUR_AWS_SES_SMTP_USERNAME',
    'pass', 'YOUR_AWS_SES_SMTP_PASSWORD',
    'senderEmail', 'noreply@yourcompany.com',
    'senderName', 'Your Company Name',
    'region', 'us-east-1',
    'configurationSet', ''
  ),
  'Active',
  0.0,
  1,
  1,
  NOW(),
  NOW()
)
ON DUPLICATE KEY UPDATE
  is_enabled = true,
  provider = 'AWS SES',
  provider_config = JSON_OBJECT(
    'host', 'email-smtp.us-east-1.amazonaws.com',
    'port', 587,
    'secure', false,
    'user', 'YOUR_AWS_SES_SMTP_USERNAME',
    'pass', 'YOUR_AWS_SES_SMTP_PASSWORD',
    'senderEmail', 'noreply@yourcompany.com',
    'senderName', 'Your Company Name',
    'region', 'us-east-1',
    'configurationSet', ''
  ),
  status = 'Active',
  updated_by = 1,
  updated_at = NOW();

-- Verify the configuration
SELECT
  id,
  channel_type,
  is_enabled,
  provider,
  status,
  JSON_EXTRACT(provider_config, '$.host') as smtp_host,
  JSON_EXTRACT(provider_config, '$.port') as smtp_port,
  JSON_EXTRACT(provider_config, '$.region') as aws_region,
  created_at,
  updated_at
FROM notification_delivery_config
WHERE channel_type = 'email';
