-- ============================================================
-- Migration: enable all 11 report-download feature flags for the TAT program type
--
-- Migration 11 seeded all 11 report-download keys (enableZoomLinksReport,
-- enableEligibleRegistrationsReport, enableSingleSessionReport [umbrella],
-- enableSingleSessionAttendanceReport, enableSessionDetailReport,
-- enableLateComerReport, enableSessionDropoffsReport, enableAttendeesLiveReport,
-- enableGeneralSessionReport, enableGeneralLateComerReport,
-- enableGeneralSessionDropoffsReport) as GLOBAL rows (program_type_id IS NULL)
-- defaulting to FALSE — opt-in per program type. This adds a TAT-scoped
-- override row (program_type_id = program_type_v1's row where
-- key = 'PT_TAT') for each of the 11 keys, set to TRUE — a
-- program-type-scoped row always wins over the global one for the same key
-- (see FeatureFlagService.isFeatureEnabledForProgramType), so this turns
-- every report on for TAT specifically while every other program type stays
-- on the global FALSE default. Looked up by program_type_v1.key rather than
-- a hardcoded id, since that id can differ across environments
-- (dev/staging/prod).
-- ============================================================

INSERT INTO feature_flag (feature_key, label, description, flag, status, program_type_id)
SELECT
  v.feature_key,
  v.label,
  v.description,
  FALSE,
  'active',
  pt.id
FROM (
  VALUES
    ('enableZoomLinksReport', 'Enable Zoom Links Report Download (TAT)', 'Toggle the "Download Zoom Links" report for TAT programs'),
    ('enableEligibleRegistrationsReport', 'Enable Eligible Registrations Report Download (TAT)', 'Toggle the Eligible Registrations screen''s "download" report for TAT programs'),
    ('enableSingleSessionReport', 'Enable Single Session Report (umbrella) (TAT)', 'Master switch for the whole single-session report screen for TAT programs'),
    ('enableSingleSessionAttendanceReport', 'Enable Single-Session Attendance Report Download (TAT)', 'Toggle the "single-session-attendance" purpose for TAT programs'),
    ('enableSessionDetailReport', 'Enable Session Detail Report Download (TAT)', 'Toggle the "session-report" (full-detail) purpose for TAT programs'),
    ('enableLateComerReport', 'Enable Late Comers Report Download (TAT)', 'Toggle the "late-comer-report" purpose for TAT programs'),
    ('enableSessionDropoffsReport', 'Enable Session Drop-offs Report Download (TAT)', 'Toggle the "session-dropoffs" purpose for TAT programs'),
    ('enableAttendeesLiveReport', 'Enable Attendees Live Report Download (TAT)', 'Toggle the General Attendees screen''s own "general-attendees" purpose for TAT programs'),
    ('enableGeneralSessionReport', 'Enable General Session Report Download (TAT)', 'Toggle the "general-session-report" purpose for TAT programs'),
    ('enableGeneralLateComerReport', 'Enable General Late Comers Report Download (TAT)', 'Toggle the "general-late-comer-report" purpose for TAT programs'),
    ('enableGeneralSessionDropoffsReport', 'Enable General Session Drop-offs Report Download (TAT)', 'Toggle the "general-session-dropoffs" purpose for TAT programs')
) AS v(feature_key, label, description)
JOIN program_type_v1 pt ON pt.key = 'PT_TAT'
ON CONFLICT (feature_key, program_type_id) WHERE program_type_id IS NOT NULL
DO UPDATE SET flag = TRUE, updated_at = CURRENT_TIMESTAMP;
