-- Demo seed data: one user + sample threads/posts so the forum is usable
-- immediately after a fresh `docker compose up`.
--
-- Password for demo / admin accounts is: demo1234
-- Hash: argon2id, m=65536, t=1, p=1 (alexedwards/argon2id default params)

INSERT INTO users (id, username, email, password_hash) VALUES
    ('00000000-0000-0000-0000-000000000001',
     'demo',
     'demo@forum.local',
     '$argon2id$v=19$m=65536,t=1,p=1$VwvftvXIO29yr7iXa/Vfyg$JcOj2Derna7Y5145ep4niqPGhzkJtB4AB/J0gxGzHbU'),
    ('00000000-0000-0000-0000-000000000002',
     'admin',
     'admin@forum.local',
     '$argon2id$v=19$m=65536,t=1,p=1$VwvftvXIO29yr7iXa/Vfyg$JcOj2Derna7Y5145ep4niqPGhzkJtB4AB/J0gxGzHbU'),
    ('00000000-0000-0000-0000-000000000003',
     'Lenny',
     'lenny.merlo@gmx.ch',
     '$argon2id$v=19$m=65536,t=1,p=6$HFN730aQZqSCUuepugNFMg$T9uVAwM+8LulHxzjM0i4y1xJGLbLhSYDIFV6DOfaxDM')
ON CONFLICT (username) DO NOTHING;

-- Welcome thread in General Discussion
WITH cat AS (SELECT id FROM categories WHERE name = 'General Discussion'),
     author AS (SELECT id FROM users WHERE username = 'admin')
INSERT INTO threads (id, category_id, author_id, title)
SELECT '00000000-0000-0000-0000-000000000010', cat.id, author.id,
       'Welcome to ForumZ!'
FROM cat, author
ON CONFLICT (id) DO NOTHING;

WITH thread AS (SELECT id FROM threads WHERE id = '00000000-0000-0000-0000-000000000010'),
     author AS (SELECT id FROM users WHERE username = 'admin')
INSERT INTO posts (thread_id, author_id, content)
SELECT thread.id, author.id,
       'Welcome to ForumZ — a distributed forum running on Go, PostgreSQL, and Nginx. ' ||
       'Feel free to introduce yourself and start a thread!'
FROM thread, author
ON CONFLICT DO NOTHING;

-- Intro thread
WITH cat AS (SELECT id FROM categories WHERE name = 'Introductions'),
     author AS (SELECT id FROM users WHERE username = 'demo')
INSERT INTO threads (id, category_id, author_id, title)
SELECT '00000000-0000-0000-0000-000000000011', cat.id, author.id,
       'Hello from the demo account!'
FROM cat, author
ON CONFLICT (id) DO NOTHING;

WITH thread AS (SELECT id FROM threads WHERE id = '00000000-0000-0000-0000-000000000011'),
     author AS (SELECT id FROM users WHERE username = 'demo')
INSERT INTO posts (thread_id, author_id, content)
SELECT thread.id, author.id,
       'Hi everyone! I''m the built-in demo user. Log in with username "demo" and password "demo1234" to try things out.'
FROM thread, author
ON CONFLICT DO NOTHING;

-- Tech Talk thread
WITH cat AS (SELECT id FROM categories WHERE name = 'Tech Talk'),
     author AS (SELECT id FROM users WHERE username = 'admin')
INSERT INTO threads (id, category_id, author_id, title)
SELECT '00000000-0000-0000-0000-000000000012', cat.id, author.id,
       'How this forum is built'
FROM cat, author
ON CONFLICT (id) DO NOTHING;

WITH thread AS (SELECT id FROM threads WHERE id = '00000000-0000-0000-0000-000000000012'),
     author AS (SELECT id FROM users WHERE username = 'admin')
INSERT INTO posts (thread_id, author_id, content)
SELECT thread.id, author.id,
       'Stack: Go 1.23 + Chi router, PostgreSQL 16, Nginx 1.27 load-balancing 3 backend replicas, React 18 frontend. ' ||
       'JWT authentication (HS256), Argon2id password hashing. ' ||
       'Single command to start: docker compose up --build'
FROM thread, author
ON CONFLICT DO NOTHING;
