-- ============================================================
-- CLEANUP DATA - Clear test/development data
-- WARNING: This will DELETE data! Use with caution!
-- ============================================================

-- ============================================================
-- OPTION 1: SOFT CLEANUP (keeps structure, removes data)
-- ============================================================

-- Clear Todos and related
DELETE FROM todo_users;
DELETE FROM todos;

-- Clear Companies and related
DELETE FROM company_remind;
DELETE FROM company_users;
DELETE FROM company_documents;
DELETE FROM companies;

-- Clear Projects and related
DELETE FROM project_users;
DELETE FROM project_documents;
DELETE FROM projects;

-- Clear Notes
DELETE FROM notes;

-- Clear Time Entries
DELETE FROM time_entries;

-- Clear Timesheets
DELETE FROM timesheets;

-- Clear Events and related
DELETE FROM event_users;
DELETE FROM events;

-- Clear Messages (both direct and group)
DELETE FROM messages;
DELETE FROM group_messages;
DELETE FROM chat_group_members;
DELETE FROM chat_groups;

-- Clear Services
DELETE FROM service_documents;
DELETE FROM service_folders;
DELETE FROM services;

-- Clear Email related (contacts, emails) - BE CAREFUL
-- DELETE FROM emails;
-- DELETE FROM contacts;

-- Clear Push subscriptions
DELETE FROM push_subscriptions;

-- Clear Email signatures
DELETE FROM email_signatures;

-- ============================================================
-- OPTION 2: RESET SEQUENCES (optional)
-- ============================================================

-- If you have serial IDs and want to reset them:
-- ALTER SEQUENCE todos_id_seq RESTART WITH 1;
-- etc.

-- ============================================================
-- VERIFY CLEANUP
-- ============================================================

SELECT 'Cleanup results:' as info;
SELECT 'Todos:' as table_name, COUNT(*) as remaining FROM todos;
SELECT 'Companies:' as table_name, COUNT(*) as remaining FROM companies;
SELECT 'Projects:' as table_name, COUNT(*) as remaining FROM projects;
SELECT 'Notes:' as table_name, COUNT(*) as remaining FROM notes;
SELECT 'Events:' as table_name, COUNT(*) as remaining FROM events;
SELECT 'Messages:' as table_name, COUNT(*) as remaining FROM messages;
SELECT 'Chat Groups:' as table_name, COUNT(*) as remaining FROM chat_groups;
SELECT 'Time Entries:' as table_name, COUNT(*) as remaining FROM time_entries;
SELECT 'Services:' as table_name, COUNT(*) as remaining FROM services;

SELECT 'Cleanup completed!' as status;
