-- Migration: Zoom Integration — Consolidated Schema
-- Description: The Zoom module reuses the platform's existing tables instead of
--              standalone hdb_zoom_* tables:
--                * webinar      -> program_session.webinar_details (jsonb, extended)
--                * registration -> hdb_program_registration (+ 1:1 zoom extension below)
--                * attendance   -> program_user_attendance.attendance_events (see
--                                  2026-06-16-02-online-attendance.sql)
-- Idempotent — safe to re-run.

-- =====================================================================


-- =====================================================================
-- 2. Online-session registration extension (1:1 with hdb_program_registration).
--    Provider-neutral per-registrant fields (zoom today, others later).
-- =====================================================================
CREATE TABLE IF NOT EXISTS hdb_program_registration_online_session (
  id                     BIGSERIAL    PRIMARY KEY,
  registration_id        BIGINT       NOT NULL UNIQUE
                           REFERENCES hdb_program_registration (id),
  provider               VARCHAR(50)  NULL,
  external_registrant_id VARCHAR(255) NULL,
  join_url               TEXT         NULL,
  is_panelist            BOOLEAN      NOT NULL DEFAULT false,
  registration_type      VARCHAR(50)  NULL,
  created_at             TIMESTAMPTZ  NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at             TIMESTAMPTZ  NOT NULL DEFAULT CURRENT_TIMESTAMP,
  deleted_at             TIMESTAMPTZ  NULL,
  created_by             BIGINT       NULL,
  updated_by             BIGINT       NULL
);

COMMENT ON TABLE hdb_program_registration_online_session IS 'Provider-neutral online-session fields for a program registration (provider, external registrant id, join url, panelist flag)';
CREATE INDEX IF NOT EXISTS idx_prog_reg_online_session_registration_id ON hdb_program_registration_online_session (registration_id);
