-- ================================================
-- Migration: PAP-009 — PT_PAP RM WhatsApp template keys
-- Date: 2026-08-08
--
-- Enum values needed by 64_pap-rm-wati-template-seed.sql. Kept in its own file so the values are
-- committed before the seed uses them — Postgres does not allow a newly ADDed enum value to be
-- used in the same transaction.
--
-- No communication_template_access_key_enum change is needed — both RM access keys already exist
-- (file 07 for REGISTRATION_COMPLETED_WATI_RM, file 20 for
-- REGISTRATION_COMPLETED_WITH_PAYMENT_WATI_RM) and both already have send sites.
--
-- Idempotent — safe to re-run.
-- ================================================

ALTER TYPE template_key_enum ADD VALUE IF NOT EXISTS 'PAP_REGISTRATION_COMPLETED_WATI_RM';
ALTER TYPE template_key_enum ADD VALUE IF NOT EXISTS 'PAP_REGISTRATION_COMPLETED_WITH_PAYMENT_WATI_RM';

-- Categories used by the two masters. Both already exist (file 07 / file 20); re-asserted so the
-- seed can run against a database that has not had file 20 applied.
ALTER TYPE communication_category_enum ADD VALUE IF NOT EXISTS 'registration_completed';
ALTER TYPE communication_category_enum ADD VALUE IF NOT EXISTS 'registration_completed_with_payment';

-- ------------------------------------------------
-- Verification
-- ------------------------------------------------
SELECT e.enumlabel
FROM pg_enum e
JOIN pg_type t ON t.oid = e.enumtypid
WHERE t.typname = 'template_key_enum'
  AND e.enumlabel LIKE 'PAP\_%WATI\_RM'
ORDER BY e.enumlabel;
