BEGIN TRANSACTION;

-- 1. CLEANUP (Optional: Remove if you want to keep existing data)
DELETE FROM "Post";
DELETE FROM "User";
DELETE FROM "sqlite_sequence"; -- Resets autoincrement counters

-- 2. CREATE USERS
-- (Passwords are all the same dummy bcrypt hash for "password123")
INSERT INTO "User" (id, email, name, display_name, password) VALUES 
(1, 'admin@forum.com', 'admin', 'SysAdmin', '$2b$10$EpWaTgiK/H/t/0W.p/h.quu/L7C7jQe5nVqg.j/z.p/h.quu/L7C7'),
(2, 'steve@moderator.com', 'mod_steve', 'Steve [MOD]', '$2b$10$EpWaTgiK/H/t/0W.p/h.quu/L7C7jQe5nVqg.j/z.p/h.quu/L7C7'),
(3, 'jane.doe@gmail.com', 'janedoe', 'Jane D.', '$2b$10$EpWaTgiK/H/t/0W.p/h.quu/L7C7jQe5nVqg.j/z.p/h.quu/L7C7'),
(4, 'rust_evangelist@tech.com', 'rusty', 'RustInPeace', '$2b$10$EpWaTgiK/H/t/0W.p/h.quu/L7C7jQe5nVqg.j/z.p/h.quu/L7C7'),
(5, 'cpp_veteran@legacy.com', 'segfault', 'C++ Grandmaster', '$2b$10$EpWaTgiK/H/t/0W.p/h.quu/L7C7jQe5nVqg.j/z.p/h.quu/L7C7'),
(6, 'troll123@hotmail.com', 'u_mad_bro', 'Anonymous', '$2b$10$EpWaTgiK/H/t/0W.p/h.quu/L7C7jQe5nVqg.j/z.p/h.quu/L7C7'),
(7, 'helpme@student.edu', 'noob_coder', 'HelpMePls', '$2b$10$EpWaTgiK/H/t/0W.p/h.quu/L7C7jQe5nVqg.j/z.p/h.quu/L7C7'),
(8, 'linux_fan@gnu.org', 'sudo_make_me', 'Arch User', '$2b$10$EpWaTgiK/H/t/0W.p/h.quu/L7C7jQe5nVqg.j/z.p/h.quu/L7C7'),
(9, 'webdev@agency.com', 'div_center', 'CSS Wizard', '$2b$10$EpWaTgiK/H/t/0W.p/h.quu/L7C7jQe5nVqg.j/z.p/h.quu/L7C7'),
(10, 'gamer@twitch.tv', 'xx_sniper_xx', 'Pro Gamer', '$2b$10$EpWaTgiK/H/t/0W.p/h.quu/L7C7jQe5nVqg.j/z.p/h.quu/L7C7'),
(11, 'bot@bot.com', 'news_bot', 'News Aggregator', '$2b$10$EpWaTgiK/H/t/0W.p/h.quu/L7C7jQe5nVqg.j/z.p/h.quu/L7C7'),
(12, 'lurker@yahoo.com', 'lurker007', NULL, '$2b$10$EpWaTgiK/H/t/0W.p/h.quu/L7C7jQe5nVqg.j/z.p/h.quu/L7C7'),
(13, 'vim@editor.com', 'vim_enthusiast', ':wq', '$2b$10$EpWaTgiK/H/t/0W.p/h.quu/L7C7jQe5nVqg.j/z.p/h.quu/L7C7'),
(14, 'emacs@editor.com', 'emacs_guru', 'M-x Butterfly', '$2b$10$EpWaTgiK/H/t/0W.p/h.quu/L7C7jQe5nVqg.j/z.p/h.quu/L7C7'),
(15, 'react@fb.com', 'hook_master', 'UseEffect', '$2b$10$EpWaTgiK/H/t/0W.p/h.quu/L7C7jQe5nVqg.j/z.p/h.quu/L7C7');


-- 3. CREATE THREADS (Top level posts)
-- We manually assign IDs here to ensure the replies attach correctly later.

-- Thread 1: Welcome (Sticky)
INSERT INTO "Post" (id, title, content, userId, parentId, createdAt) VALUES 
(1, 'Welcome to the Community! READ FIRST', 'Welcome everyone. Please be nice. No spamming. Enjoy your stay!', 1, NULL, datetime('now', '-30 days'));

-- Thread 2: Flame war (Tabs vs Spaces)
INSERT INTO "Post" (id, title, content, userId, parentId, createdAt) VALUES 
(2, 'Unpopular Opinion: Spaces are objectively better than Tabs', 'I said what I said. If you use tabs, your formatting is at the mercy of the editor settings. Discuss.', 3, NULL, datetime('now', '-15 days'));

-- Thread 3: Tech Support
INSERT INTO "Post" (id, title, content, userId, parentId, createdAt) VALUES 
(3, 'URGENT: Cannot exit Vim?', 'I have been stuck in Vim for 4 days. I have tried Esc, Ctrl+C, Alt+F4. I am starving. Please help.', 7, NULL, datetime('now', '-2 days'));

-- Thread 4: Gaming
INSERT INTO "Post" (id, title, content, userId, parentId, createdAt) VALUES 
(4, 'Elden Ring DLC discussion', 'Has anyone beaten the final boss yet? No spoilers please, but that second phase is brutal.', 10, NULL, datetime('now', '-5 days'));

-- Thread 5: Programming Language War
INSERT INTO "Post" (id, title, content, userId, parentId, createdAt) VALUES 
(5, 'Why Rust will replace C++ in 5 years', 'Memory safety is not optional anymore. The borrow checker is your friend.', 4, NULL, datetime('now', '-10 days'));

-- Thread 6: Off Topic Megathread (This will house most of the "volume")
INSERT INTO "Post" (id, title, content, userId, parentId, createdAt) VALUES 
(6, 'MEGATHREAD: What are you listening to right now?', 'Post your current jam. Keep it clean.', 2, NULL, datetime('now', '-60 days'));

-- Thread 7: Random
INSERT INTO "Post" (id, title, content, userId, parentId, createdAt) VALUES 
(7, 'My cat walked on my keyboard and deployed to production', 'Fortunately, the tests passed. I think my cat is a better dev than me.', 9, NULL, datetime('now', '-1 day'));

-- Thread 8: News
INSERT INTO "Post" (id, title, content, userId, parentId, createdAt) VALUES 
(8, 'Tech News: AI takes over toaster industry', 'Smart toasters are now requiring a subscription to toast bagels.', 11, NULL, datetime('now', '-20 days'));


-- 4. CREATE REALISTIC REPLIES
-- Thread 1 (Welcome) Replies
INSERT INTO "Post" (title, content, userId, parentId, createdAt) VALUES 
('Re: Welcome', 'Thanks admin! Glad to be here.', 3, 1, datetime('now', '-29 days')),
('Re: Welcome', 'First!', 6, 1, datetime('now', '-29 days')),
('Re: Welcome', 'Please do not post "First", this is not YouTube.', 2, 1, datetime('now', '-29 days')),
('Re: Welcome', 'Hello world.', 5, 1, datetime('now', '-28 days'));

-- Thread 2 (Tabs vs Spaces) - The Fight
INSERT INTO "Post" (title, content, userId, parentId, createdAt) VALUES 
('Re: Tabs vs Spaces', 'You are wrong. Tabs save file size. Imagine a 1MB file, tabs save bytes!', 5, 2, datetime('now', '-14 days')),
('Re: Tabs vs Spaces', 'Storage is cheap. Consistency is priceless. Spaces all the way.', 9, 2, datetime('now', '-14 days')),
('Re: Tabs vs Spaces', 'I use a mix of both just to annoy my coworkers.', 6, 2, datetime('now', '-14 days')),
('Re: Tabs vs Spaces', 'You monster.', 3, 2, datetime('now', '-13 days')),
('Re: Tabs vs Spaces', 'Go style guide says tabs. I follow the Go style guide.', 4, 2, datetime('now', '-13 days')),
('Re: Tabs vs Spaces', 'Python enforces indentation. Spaces are the standard there.', 8, 2, datetime('now', '-13 days'));

-- Thread 3 (Vim Help)
INSERT INTO "Post" (title, content, userId, parentId, createdAt) VALUES 
('Re: Vim', 'Type :q! and hit enter.', 13, 3, datetime('now', '-2 days')),
('Re: Vim', 'Or just unplug your computer.', 6, 3, datetime('now', '-2 days')),
('Re: Vim', 'Just switch to Emacs, we have a menu bar.', 14, 3, datetime('now', '-2 days')),
('Re: Vim', 'OMG THANK YOU @vim_enthusiast you saved my life.', 7, 3, datetime('now', '-1 day'));

-- Thread 5 (Rust vs C++)
INSERT INTO "Post" (title, content, userId, parentId, createdAt) VALUES 
('Re: Rust', 'C++ is still faster if you know what you are doing.', 5, 5, datetime('now', '-9 days')),
('Re: Rust', 'Most people do not know what they are doing though.', 4, 5, datetime('now', '-9 days')),
('Re: Rust', 'Rewriting everything in Rust is not feasible for large legacy codebases.', 1, 5, datetime('now', '-8 days')),
('Re: Rust', 'Agreed, but for greenfield projects it is a no brainer.', 9, 5, datetime('now', '-8 days')),
('Re: Rust', 'I like Zig.', 8, 5, datetime('now', '-7 days'));

-- Thread 7 (Cat deployment)
INSERT INTO "Post" (title, content, userId, parentId, createdAt) VALUES 
('Re: Cat', 'Is the cat looking for a job? We are hiring.', 1, 7, datetime('now', '-23 hours')),
('Re: Cat', 'Pics or it didnt happen.', 6, 7, datetime('now', '-20 hours')),
('Re: Cat', 'Mine just sleeps on the warm laptop vent.', 15, 7, datetime('now', '-10 hours'));


-- 5. GENERATE BULK VOLUME (The "Megathread")
-- We use a recursive query or just a massive block of inserts to hit ~500 posts.
-- We will simulate a "What are you listening to" thread (Parent ID 6).

INSERT INTO "Post" (title, content, userId, parentId, createdAt) VALUES
('Song', 'Pink Floyd - Echoes', 8, 6, datetime('now', '-59 days')),
('Song', 'Daft Punk - Discovery (Whole Album)', 9, 6, datetime('now', '-58 days')),
('Song', 'Lo-fi beats to study to', 7, 6, datetime('now', '-58 days')),
('Song', 'Metallica - Master of Puppets', 5, 6, datetime('now', '-57 days')),
('Song', 'Darude - Sandstorm', 6, 6, datetime('now', '-56 days')),
('Song', 'Rick Astley - Never Gonna Give You Up', 6, 6, datetime('now', '-56 days')),
('Song', 'Bach - Cello Suite No. 1', 3, 6, datetime('now', '-55 days')),
('Song', 'Kendrick Lamar - DNA', 15, 6, datetime('now', '-54 days')),
('Song', 'Tool - Lateralus', 4, 6, datetime('now', '-53 days')),
('Song', 'Taylor Swift', 10, 6, datetime('now', '-52 days')),
('Song', '+1 for Tool', 8, 6, datetime('now', '-52 days')),
('Song', 'Radiohead - OK Computer', 2, 6, datetime('now', '-50 days')),
('Song', 'Video Game OSTs mostly', 10, 6, datetime('now', '-49 days')),
('Song', 'Aphex Twin', 11, 6, datetime('now', '-48 days')),
('Song', 'Silence. My fans are too loud.', 12, 6, datetime('now', '-47 days')),
('Song', 'Jazz vibes', 14, 6, datetime('now', '-46 days'));

-- To get to 500 without writing 500 lines manually, we will use a cross join trick
-- to multiply these generic comments into the megathread (ID 6).

INSERT INTO "Post" (title, content, userId, parentId, createdAt)
SELECT 
  'Re: Music', 
  'Listening to track #' || (ABS(RANDOM()) % 1000), 
  (ABS(RANDOM()) % 15) + 1, -- Random User ID 1-15
  6, -- Parent ID 6 (Music Thread)
  datetime('now', '-' || (ABS(RANDOM()) % 60) || ' days')
FROM "User" u1, "User" u2, "User" u3
LIMIT 300; -- Adds 300 generic posts

-- Add some random replies to the Rust vs C++ thread (ID 5) to make it look heated
INSERT INTO "Post" (title, content, userId, parentId, createdAt)
SELECT 
  'Re: Rust vs C++', 
  CASE (ABS(RANDOM()) % 5)
    WHEN 0 THEN 'I disagree strongly.'
    WHEN 1 THEN 'This is the way.'
    WHEN 2 THEN 'Have you read the documentation?'
    WHEN 3 THEN 'Benchmarks prove otherwise.'
    ELSE 'Interesting point.'
  END,
  (ABS(RANDOM()) % 15) + 1, 
  5, -- Parent ID 5
  datetime('now', '-' || (ABS(RANDOM()) % 10) || ' days')
FROM "User" u1, "User" u2
LIMIT 50;

-- Add some "Bump" posts to random threads
INSERT INTO "Post" (title, content, userId, parentId, createdAt)
SELECT 
  'Bump', 
  'Bumping this thread.', 
  (ABS(RANDOM()) % 15) + 1, 
  (ABS(RANDOM()) % 8) + 1, -- Random Parent ID 1-8
  datetime('now', '-1 hour')
FROM "User"
LIMIT 20;

COMMIT;
