-- ================================================
-- Migration: PAP-003 — PT_PAP WhatsApp (WATI) template keys
-- Date: 2026-08-08
--
-- Enum values needed by 58_pap-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.
--
-- NOTE: no communication_template_access_key_enum change is needed. All six PAP WhatsApp
-- messages reuse access keys that already exist and already have send sites:
--   1. Registration completion          -> REGISTRATION_COMPLETED_WATI_SEEKER
--   2. Registration approved            -> BLESSED_WATI_SEEKER
--   3. Online registration confirmed    -> ONLINE_PAYMENT_COMPLETED_WATI_SEEKER
--   4. Invoice                          -> INVOICE_WATI_SEEKER
--   5. Offline payment acknowledgement  -> PAYMENT_ACKNOWLEDGEMENT_OFFLINE_WATI_SEEKER
--   6. Offline payment confirmed        -> OFFLINE_PAYMENT_COMPLETED_WATI_SEEKER
-- (The email side needed one new key, OFFLINE_PAYMENT_COMPLETED_EMAIL_SEEKER — see file 55 —
-- because offline realization previously notified over WhatsApp only.)
--
-- Idempotent — safe to re-run.
-- ================================================

ALTER TYPE template_key_enum ADD VALUE IF NOT EXISTS 'PAP_REGISTRATION_COMPLETED_WATI_SEEKER';
ALTER TYPE template_key_enum ADD VALUE IF NOT EXISTS 'PAP_BLESSED_WATI_SEEKER';
ALTER TYPE template_key_enum ADD VALUE IF NOT EXISTS 'PAP_ONLINE_PAYMENT_COMPLETED_WATI_SEEKER';
ALTER TYPE template_key_enum ADD VALUE IF NOT EXISTS 'PAP_INVOICE_WATI_SEEKER';
ALTER TYPE template_key_enum ADD VALUE IF NOT EXISTS 'PAP_PAYMENT_ACKNOWLEDGEMENT_OFFLINE_WATI_SEEKER';
ALTER TYPE template_key_enum ADD VALUE IF NOT EXISTS 'PAP_OFFLINE_PAYMENT_COMPLETED_WATI_SEEKER';

-- ------------------------------------------------
-- 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\_%'
ORDER BY e.enumlabel;

