-- =========================================================
-- CLEANUP & FRESH INSTALL SCRIPT
-- =========================================================
-- This script will:
-- 1. DELETE all existing "Threat Intelligence" data (cleaning up duplicates)
-- 2. RE-CREATE the course from scratch (ensuring 1 clean copy)
-- =========================================================

-- 1. Delete Lesson Content
DELETE lc FROM lesson_content lc 
INNER JOIN tasks t ON lc.task_id = t.id 
INNER JOIN modules m ON t.module_id = m.id 
INNER JOIN learning_paths lp ON m.learning_path_id = lp.id 
WHERE lp.title = 'Threat Intelligence';

-- 2. Delete Quiz Questions
DELETE lq FROM lesson_questions lq
INNER JOIN tasks t ON lq.task_id = t.id 
INNER JOIN modules m ON t.module_id = m.id 
INNER JOIN learning_paths lp ON m.learning_path_id = lp.id 
WHERE lp.title = 'Threat Intelligence';

-- 3. Delete Tasks
DELETE t FROM tasks t
INNER JOIN modules m ON t.module_id = m.id 
INNER JOIN learning_paths lp ON m.learning_path_id = lp.id 
WHERE lp.title = 'Threat Intelligence';

-- 4. Delete Modules
DELETE m FROM modules m
INNER JOIN learning_paths lp ON m.learning_path_id = lp.id 
WHERE lp.title = 'Threat Intelligence';

-- 5. Delete the Learning Paths (all duplicates)
DELETE FROM learning_paths WHERE title = 'Threat Intelligence';

-- =========================================================
-- FRESH INSTALL STARTS HERE
-- =========================================================
