-- nuclear-cleanup.sql
-- Step 1: show what enum types currently exist related to our blocks
SELECT typname FROM pg_type 
WHERE typname LIKE '%lm_service_cards%' 
   OR typname LIKE '%lm_product_detail%'
ORDER BY typname;

-- Step 2: Drop everything with DO block so we can be dynamic
DO $$
DECLARE
  r RECORD;
BEGIN
  FOR r IN
    SELECT typname FROM pg_type
    WHERE typname LIKE '%lm_service_cards%'
       OR typname LIKE '%lm_product_detail%'
  LOOP
    EXECUTE 'DROP TYPE IF EXISTS public.' || quote_ident(r.typname) || ' CASCADE';
    RAISE NOTICE 'Dropped type: %', r.typname;
  END LOOP;
END $$;

-- Step 3: Drop tables
DO $$
DECLARE
  r RECORD;
BEGIN
  FOR r IN
    SELECT tablename FROM pg_tables
    WHERE schemaname = 'public'
      AND (tablename LIKE '%lm_service_cards%'
        OR tablename LIKE '%lm_product_detail%')
  LOOP
    EXECUTE 'DROP TABLE IF EXISTS public.' || quote_ident(r.tablename) || ' CASCADE';
    RAISE NOTICE 'Dropped table: %', r.tablename;
  END LOOP;
END $$;

-- Step 4: Confirm nothing left
SELECT typname FROM pg_type 
WHERE typname LIKE '%lm_service_cards%' 
   OR typname LIKE '%lm_product_detail%';
