-- Migration: Activation toggle on the online-session extension
-- Date: 2026-07-13
-- Description:
--   Admin/RM/Shoba can deactivate a seat-eligible registrant for ONE online
--   session (removing their Zoom join link) and reactivate them later
--   (re-provisioning it). This is a human toggle, independent of `status`
--   (provisioning outcome) already on this table.
--
--     activation_status     -- 'active' (default) | 'inactive'
--     activation_changed_at -- when the toggle last ran for this pair
--     activation_changed_by -- user id who last toggled it
--     activation_reason     -- optional free-text note captured with the toggle
--
-- Additive and idempotent. Existing rows all default to 'active'.

ALTER TABLE hdb_program_registration_online_session
    ADD COLUMN IF NOT EXISTS activation_status VARCHAR(20) NOT NULL DEFAULT 'active';

COMMENT ON COLUMN hdb_program_registration_online_session.activation_status IS
    'Human toggle: is this registrant currently active for this session (holds a live join link) or deactivated by an admin/RM/Shoba. Independent of status (provisioning outcome).';

ALTER TABLE hdb_program_registration_online_session
    ADD COLUMN IF NOT EXISTS activation_changed_at TIMESTAMPTZ NULL;

COMMENT ON COLUMN hdb_program_registration_online_session.activation_changed_at IS
    'When activation_status was last changed for this pair.';

ALTER TABLE hdb_program_registration_online_session
    ADD COLUMN IF NOT EXISTS activation_changed_by INT NULL;

COMMENT ON COLUMN hdb_program_registration_online_session.activation_changed_by IS
    'User id who last changed activation_status for this pair.';

ALTER TABLE hdb_program_registration_online_session
    ADD COLUMN IF NOT EXISTS activation_reason TEXT NULL;

COMMENT ON COLUMN hdb_program_registration_online_session.activation_reason IS
    'Optional free-text note captured with the last activation change.';

-- Fast "who's currently inactive for a session" scans.
CREATE INDEX IF NOT EXISTS idx_prog_reg_online_session_activation
    ON hdb_program_registration_online_session (online_session_id, activation_status)
    WHERE deleted_at IS NULL;
