-- =====================================================
-- Location venue map — backfill for existing program types (program_type_v1 + program_v1)
-- 2026-08-18
-- DRAFT ONLY — not executed against any database, not yet reviewed/approved.
-- Data only. Idempotent (plain UPDATE ... SET, safe to re-run).
-- =====================================================
--
-- Backfills the location_venue_map column added by
-- 2026-08-18-01-add-location-venue-map-column.sql, one row per program type (all 5 that
-- exist in this repo's seed data — see database/program-configuration/15_sync_program_type_
-- master_data.sql for HDB/TAT/ENTRAINMENT/CUSTOM, database/migrations/2026-08-08-12-pt-pap-
-- venue-update.sql for PAP). Value is a plain Google Maps search-query deep link
-- (https://www.google.com/maps/search/?api=1&query=<address>) built from each type's existing
-- `venue` address text — no coordinates or Maps API key assumed, this resolves for any address
-- string.
--
-- Per explicit instruction:
--   - PT_TAT:         online-only, no physical venue (venue = 'Online Webinar') -> NULL
--   - PT_HDBMSD:      Leonia Holistic Destination, Hyderabad -> map link
--   - PT_ENTRAINMENT: same Leonia Holistic Destination, Hyderabad venue -> same map link
--   - PT_PAP:         confirmed set (Radisson Blu Resort Temple Bay, Mamallapuram, per
--                      2026-08-08-12-pt-pap-venue-update.sql) -> map link
--   - CUSTOM:         per-program, not per-type (venue = NULL on this row too) -> NULL
--
-- Also updates program_v1 for any already-created programs under these types, whose own
-- venue/venue_name_in_emails were copied from program_type_v1 at creation time and won't pick
-- up this fill retroactively otherwise — mirrors 2026-08-08-12-pt-pap-venue-update.sql's own
-- two-target (program_type_v1 + program_v1) pattern. TAT/CUSTOM programs are included in the
-- explicit NULL statements below too, purely for idempotency (guards against a stray value),
-- not because any is expected to exist.
-- =====================================================

-- ── HDB/MSD + ENTRAINMENT (shared venue: Leonia Holistic Destination, Hyderabad) ──

UPDATE program_type_v1
SET location_venue_map = 'https://www.google.com/maps/search/?api=1&query=Leonia+Holistic+Destination%2C+Bommarasipet%2C+Shamirpet+Mandal%2C+Medchal-Malkajgiri+District%2C+Hyderabad+-+500078.',
    updated_at         = NOW(),
    updated_by         = -2
WHERE key IN ('PT_HDBMSD', 'PT_ENTRAINMENT')
  AND deleted_at IS NULL;

UPDATE program_v1 p
SET location_venue_map = 'https://www.google.com/maps/search/?api=1&query=Leonia+Holistic+Destination%2C+Bommarasipet%2C+Shamirpet+Mandal%2C+Medchal-Malkajgiri+District%2C+Hyderabad+-+500078.',
    updated_at         = NOW(),
    updated_by         = -2
WHERE p.deleted_at IS NULL
  AND p.program_type_id IN (
        SELECT id FROM program_type_v1 WHERE key IN ('PT_HDBMSD', 'PT_ENTRAINMENT') AND deleted_at IS NULL
  );

-- ── PAP (Radisson Blu Resort Temple Bay, Mamallapuram) ──

UPDATE program_type_v1
SET location_venue_map = 'https://www.google.com/maps/search/?api=1&query=Radisson+Blu+Resort+Temple+Bay%2C+57%2C+Covelong+Road%2C+Mamallapuram%2C+Tamil+Nadu+%E2%80%93+603104.',
    updated_at         = NOW(),
    updated_by         = -2
WHERE key = 'PT_PAP'
  AND deleted_at IS NULL;

UPDATE program_v1 p
SET location_venue_map = 'https://www.google.com/maps/search/?api=1&query=Radisson+Blu+Resort+Temple+Bay%2C+57%2C+Covelong+Road%2C+Mamallapuram%2C+Tamil+Nadu+%E2%80%93+603104.',
    updated_at         = NOW(),
    updated_by         = -2
WHERE p.deleted_at IS NULL
  AND p.program_type_id IN (
        SELECT id FROM program_type_v1 WHERE key = 'PT_PAP' AND deleted_at IS NULL
  );

-- ── TAT + CUSTOM: no physical venue — explicit NULL for idempotency ──

UPDATE program_type_v1
SET location_venue_map = NULL,
    updated_at         = NOW(),
    updated_by         = -2
WHERE key IN ('PT_TAT', 'CUSTOM')
  AND deleted_at IS NULL;

UPDATE program_v1 p
SET location_venue_map = NULL,
    updated_at         = NOW(),
    updated_by         = -2
WHERE p.deleted_at IS NULL
  AND p.program_type_id IN (
        SELECT id FROM program_type_v1 WHERE key IN ('PT_TAT', 'CUSTOM') AND deleted_at IS NULL
  );
