-- 119_notification_whatsapp_internal_feature.sql
-- Feature gate internal-only untuk producer/dispatch WhatsApp sementara.

INSERT INTO platform_features (code, name, domain, description, is_active, sort_order)
SELECT
  'notification.whatsapp_internal',
  'WhatsApp Internal Notifications',
  'operations',
  'Gate internal-only untuk notifikasi WhatsApp sementara berbasis worker internal.',
  1,
  174
WHERE NOT EXISTS (
  SELECT 1
  FROM platform_features
  WHERE code = 'notification.whatsapp_internal'
);

UPDATE platform_features
SET
  name = 'WhatsApp Internal Notifications',
  domain = 'operations',
  description = 'Gate internal-only untuk notifikasi WhatsApp sementara berbasis worker internal.',
  is_active = 1,
  sort_order = 174
WHERE code = 'notification.whatsapp_internal';

INSERT INTO platform_plan_features (platform_plan_id, platform_feature_id, is_enabled)
SELECT pp.id, pf.id, 0
FROM platform_plans pp
INNER JOIN platform_features pf ON pf.code = 'notification.whatsapp_internal'
WHERE NOT EXISTS (
  SELECT 1
  FROM platform_plan_features ppf
  WHERE ppf.platform_plan_id = pp.id
    AND ppf.platform_feature_id = pf.id
);

UPDATE platform_plan_features ppf
INNER JOIN platform_features pf ON pf.id = ppf.platform_feature_id
SET ppf.is_enabled = 0
WHERE pf.code = 'notification.whatsapp_internal';
