-- Simple fix for moving Gmail/YouTube from Productive to Browser category
-- This version avoids any complex functions that might cause errors

\echo Moving Gmail, YouTube, and social media from Productive to Browser category...

BEGIN;

-- Update Gmail
UPDATE activity_records
SET category = 'browser'
WHERE category = 'productive'
AND (LOWER(window_title) LIKE '%gmail%' OR LOWER(url) LIKE '%mail.google.com%');

-- Update YouTube  
UPDATE activity_records
SET category = 'browser'
WHERE category = 'productive'
AND (LOWER(window_title) LIKE '%youtube%' OR LOWER(url) LIKE '%youtube.com%' OR LOWER(url) LIKE '%youtu.be%');

-- Update Facebook
UPDATE activity_records
SET category = 'browser'
WHERE category = 'productive'
AND LOWER(window_title) LIKE '%facebook%';

-- Update Instagram
UPDATE activity_records
SET category = 'browser'
WHERE category = 'productive'
AND LOWER(window_title) LIKE '%instagram%';

-- Update Twitter
UPDATE activity_records
SET category = 'browser'
WHERE category = 'productive'
AND LOWER(window_title) LIKE '%twitter%';

-- Update Reddit
UPDATE activity_records
SET category = 'browser'
WHERE category = 'productive'
AND LOWER(window_title) LIKE '%reddit%';

-- Update Netflix
UPDATE activity_records
SET category = 'browser'
WHERE category = 'productive'
AND LOWER(window_title) LIKE '%netflix%';

-- Update Spotify
UPDATE activity_records
SET category = 'browser'
WHERE category = 'productive'
AND LOWER(window_title) LIKE '%spotify%';

COMMIT;

-- Show simple count of each category
SELECT category, COUNT(*) as total_activities
FROM activity_records
WHERE timestamp > CURRENT_DATE - INTERVAL '7 days'
GROUP BY category
ORDER BY total_activities DESC;

\echo Done! Gmail, YouTube, and social media have been moved to Browser category.