-- Migration: SC-011 — Common Invite (PER-SESSION) enums (access keys + template keys)
-- Description: Enum values for the per-session variant of the Common-Invite communication
--              (email + WhatsApp). Same audience as the program-level common invite (the staff
--              issued a generated common Zoom link), but scoped to ONE session — used when the
--              program's links are generated per session (SessionLinkModeEnum.PER_SESSION) so the
--              message carries that session's name / date / time.
--              Kept in its own file so the values are committed before the seed
--              (43_common-invite-per-session-template-seed.sql) uses them — Postgres does not
--              allow a newly ADDed enum value to be used in the same transaction.
-- Idempotent — safe to re-run.

-- ------------------------------------------------
-- communication_template_access_key_enum — the send-time access keys
-- ------------------------------------------------
ALTER TYPE communication_template_access_key_enum ADD VALUE IF NOT EXISTS 'COMMON_INVITE_PER_SESSION_EMAIL_SEEKER';
ALTER TYPE communication_template_access_key_enum ADD VALUE IF NOT EXISTS 'COMMON_INVITE_PER_SESSION_WATI_SEEKER';

-- ------------------------------------------------
-- template_key_enum — the master/clone template keys seeded in file 43 (PT_TAT)
-- ------------------------------------------------
ALTER TYPE template_key_enum ADD VALUE IF NOT EXISTS 'TAT_COMMON_INVITE_PER_SESSION_EMAIL_SEEKER';
ALTER TYPE template_key_enum ADD VALUE IF NOT EXISTS 'TAT_COMMON_INVITE_PER_SESSION_WATI_SEEKER';

-- ------------------------------------------------
-- Verification
-- ------------------------------------------------
SELECT enumlabel
FROM pg_enum e
JOIN pg_type t ON t.oid = e.enumtypid
WHERE t.typname = 'communication_template_access_key_enum'
  AND e.enumlabel IN ('COMMON_INVITE_PER_SESSION_EMAIL_SEEKER', 'COMMON_INVITE_PER_SESSION_WATI_SEEKER')
ORDER BY enumlabel;

SELECT enumlabel
FROM pg_enum e
JOIN pg_type t ON t.oid = e.enumtypid
WHERE t.typname = 'template_key_enum'
  AND e.enumlabel IN ('TAT_COMMON_INVITE_PER_SESSION_EMAIL_SEEKER', 'TAT_COMMON_INVITE_PER_SESSION_WATI_SEEKER')
ORDER BY enumlabel;
