-- 1. Generate 100 Users
-- Password is a bcrypt hash for "password123"
INSERT INTO "User" (email, name, display_name, password)
WITH RECURSIVE
  cnt(n) AS (
     SELECT 1
     UNION ALL
     SELECT n+1 FROM cnt WHERE n < 100
  )
SELECT 
  'user' || n || '@example.com',
  'user_' || n,
  'User ' || n,
  '$2b$10$EpjVIByL7WqitL96.t65he1usN8L6j0r6n/1q7R8U6O1Y2v6y/L2.' -- password123
FROM cnt;

-- 2. Generate 700 Parent Posts
-- Distributed across the 100 users
INSERT INTO "Post" (title, content, userId, createdAt)
WITH RECURSIVE
  cnt(n) AS (
     SELECT 1
     UNION ALL
     SELECT n+1 FROM cnt WHERE n < 700
  )
SELECT 
  'Post Title #' || n,
  'This is the body content for sample post number ' || n || '. It contains some placeholder text for testing purposes.',
  (ABS(RANDOM()) % 100) + 1, -- Random userId between 1 and 100
  datetime('now', '-' || (ABS(RANDOM()) % 365) || ' days') -- Random date in the last year
FROM cnt;

-- 3. Generate 200 Replies
-- Linked to random parent posts (IDs 1-700)
INSERT INTO "Post" (title, content, userId, parentId, createdAt)
WITH RECURSIVE
  cnt(n) AS (
     SELECT 1
     UNION ALL
     SELECT n+1 FROM cnt WHERE n < 200
  )
SELECT 
  'Reply #' || n,
  'I am replying to an existing post to test the self-relation logic.',
  (ABS(RANDOM()) % 100) + 1, -- Random author
  (ABS(RANDOM()) % 700) + 1, -- Random parent post ID
  datetime('now', '-' || (ABS(RANDOM()) % 30) || ' days') -- Random date in last 30 days
FROM cnt;
