-- ==============================================
-- We Talk — Seed Data
-- Podcasts libres de droit (Creative Commons)
-- Source: Hacker Public Radio (archive.org)
-- ==============================================

-- 1. Create demo users in auth.users first (required for FK on profiles)
-- NOTE: Run this AFTER the migration 001_initial_schema.sql

INSERT INTO auth.users (id, instance_id, email, encrypted_password, email_confirmed_at, aud, role, raw_app_meta_data, raw_user_meta_data, created_at, updated_at, confirmation_token) VALUES
  ('a1000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000000', 'ahuka@demo.wetalk.fr', crypt('demo-password-123', gen_salt('bf')), NOW(), 'authenticated', 'authenticated', '{"provider":"email","providers":["email"]}', '{"username":"ahuka"}', NOW(), NOW(), ''),
  ('a1000000-0000-0000-0000-000000000002', '00000000-0000-0000-0000-000000000000', 'sgoti@demo.wetalk.fr', crypt('demo-password-123', gen_salt('bf')), NOW(), 'authenticated', 'authenticated', '{"provider":"email","providers":["email"]}', '{"username":"sgoti"}', NOW(), NOW(), ''),
  ('a1000000-0000-0000-0000-000000000003', '00000000-0000-0000-0000-000000000000', 'klaatu@demo.wetalk.fr', crypt('demo-password-123', gen_salt('bf')), NOW(), 'authenticated', 'authenticated', '{"provider":"email","providers":["email"]}', '{"username":"klaatu"}', NOW(), NOW(), ''),
  ('a1000000-0000-0000-0000-000000000004', '00000000-0000-0000-0000-000000000000', 'windigo@demo.wetalk.fr', crypt('demo-password-123', gen_salt('bf')), NOW(), 'authenticated', 'authenticated', '{"provider":"email","providers":["email"]}', '{"username":"windigo"}', NOW(), NOW(), ''),
  ('a1000000-0000-0000-0000-000000000005', '00000000-0000-0000-0000-000000000000', 'corydoctorow@demo.wetalk.fr', crypt('demo-password-123', gen_salt('bf')), NOW(), 'authenticated', 'authenticated', '{"provider":"email","providers":["email"]}', '{"username":"corydoctorow"}', NOW(), NOW(), '')
ON CONFLICT (id) DO NOTHING;

-- Also insert into auth.identities (required by Supabase Auth)
INSERT INTO auth.identities (id, user_id, provider_id, provider, identity_data, last_sign_in_at, created_at, updated_at) VALUES
  ('a1000000-0000-0000-0000-000000000001', 'a1000000-0000-0000-0000-000000000001', 'a1000000-0000-0000-0000-000000000001', 'email', '{"sub":"a1000000-0000-0000-0000-000000000001","email":"ahuka@demo.wetalk.fr"}', NOW(), NOW(), NOW()),
  ('a1000000-0000-0000-0000-000000000002', 'a1000000-0000-0000-0000-000000000002', 'a1000000-0000-0000-0000-000000000002', 'email', '{"sub":"a1000000-0000-0000-0000-000000000002","email":"sgoti@demo.wetalk.fr"}', NOW(), NOW(), NOW()),
  ('a1000000-0000-0000-0000-000000000003', 'a1000000-0000-0000-0000-000000000003', 'a1000000-0000-0000-0000-000000000003', 'email', '{"sub":"a1000000-0000-0000-0000-000000000003","email":"klaatu@demo.wetalk.fr"}', NOW(), NOW(), NOW()),
  ('a1000000-0000-0000-0000-000000000004', 'a1000000-0000-0000-0000-000000000004', 'a1000000-0000-0000-0000-000000000004', 'email', '{"sub":"a1000000-0000-0000-0000-000000000004","email":"windigo@demo.wetalk.fr"}', NOW(), NOW(), NOW()),
  ('a1000000-0000-0000-0000-000000000005', 'a1000000-0000-0000-0000-000000000005', 'a1000000-0000-0000-0000-000000000005', 'email', '{"sub":"a1000000-0000-0000-0000-000000000005","email":"corydoctorow@demo.wetalk.fr"}', NOW(), NOW(), NOW())
ON CONFLICT (id) DO NOTHING;

-- Now insert profiles (the trigger handle_new_user won't fire on direct auth.users inserts)
INSERT INTO public.profiles (id, username, avatar_url, bio, is_premium, free_listens_count) VALUES
  ('a1000000-0000-0000-0000-000000000001', 'ahuka', NULL, 'Passionné de technologie et de logiciels libres. Contributeur Hacker Public Radio.', true, 0),
  ('a1000000-0000-0000-0000-000000000002', 'sgoti', NULL, 'Podcaster et bricoleur informatique. J''aime parler de tout et de rien.', false, 3),
  ('a1000000-0000-0000-0000-000000000003', 'klaatu', NULL, 'Explorateur numerique. Voyage, technologie et culture libre.', true, 0),
  ('a1000000-0000-0000-0000-000000000004', 'windigo', NULL, 'Administrateur systeme le jour, podcaster la nuit.', false, 7),
  ('a1000000-0000-0000-0000-000000000005', 'corydoctorow', NULL, 'Auteur, journaliste, activiste. Electronic Frontier Foundation.', true, 0)
ON CONFLICT (id) DO NOTHING;

-- 2. Create tags
INSERT INTO public.tags (id, name, slug) VALUES
  ('b1000000-0000-0000-0000-000000000001', 'Technologie', 'technologie'),
  ('b1000000-0000-0000-0000-000000000002', 'Open Source', 'open-source'),
  ('b1000000-0000-0000-0000-000000000003', 'Jeux Video', 'jeux-video'),
  ('b1000000-0000-0000-0000-000000000004', 'Tutoriel', 'tutoriel'),
  ('b1000000-0000-0000-0000-000000000005', 'Culture', 'culture'),
  ('b1000000-0000-0000-0000-000000000006', 'Voyage', 'voyage'),
  ('b1000000-0000-0000-0000-000000000007', 'Productivite', 'productivite'),
  ('b1000000-0000-0000-0000-000000000008', 'Vie Quotidienne', 'vie-quotidienne'),
  ('b1000000-0000-0000-0000-000000000009', 'Droit Numerique', 'droit-numerique'),
  ('b1000000-0000-0000-0000-000000000010', 'Windows', 'windows'),
  ('b1000000-0000-0000-0000-000000000011', 'Linux', 'linux'),
  ('b1000000-0000-0000-0000-000000000012', 'Podcasting', 'podcasting')
ON CONFLICT (id) DO NOTHING;

-- 3. Insert podcasts (audio from archive.org, Creative Commons)
INSERT INTO public.podcasts (id, creator_id, title, description, audio_url, duration_seconds, cover_url, plays_count, created_at) VALUES
  (
    'c1000000-0000-0000-0000-000000000001',
    'a1000000-0000-0000-0000-000000000001',
    'Creative Commons Search Engine',
    'Decouvrez Openverse, le nouveau moteur de recherche pour le contenu Creative Commons. Une evolution de l''ancien CC Search developpe par Creative Commons, repris par WordPress, et qui continue d''evoluer.',
    'https://archive.org/download/hpr3977/hpr3977.mp3',
    358,
    NULL,
    247,
    NOW() - INTERVAL '2 days'
  ),
  (
    'c1000000-0000-0000-0000-000000000002',
    'a1000000-0000-0000-0000-000000000003',
    'Playing Alpha Centauri, Part 1',
    'Premiere partie de nos conseils pour jouer a Alpha Centauri. On commence par regarder comment approcher ce jeu de strategie classique et les bases pour bien demarrer.',
    'https://archive.org/download/hpr3970/hpr3970.mp3',
    1102,
    NULL,
    183,
    NOW() - INTERVAL '5 days'
  ),
  (
    'c1000000-0000-0000-0000-000000000003',
    'a1000000-0000-0000-0000-000000000002',
    'Comment se faire des amis sur Internet',
    'Sgoti et Mugs discutent avec des amis de la facon de creer des liens authentiques en ligne. Un echange decontracte sur les relations humaines a l''ere du numerique.',
    'https://archive.org/download/hpr3971/hpr3971.mp3',
    2245,
    NULL,
    412,
    NOW() - INTERVAL '3 days'
  ),
  (
    'c1000000-0000-0000-0000-000000000004',
    'a1000000-0000-0000-0000-000000000002',
    'Filtrage Thunderbird : garder une boite mail propre',
    'Sgoti explique comment filtrer efficacement votre boite de reception Thunderbird pour rester organise et productif au quotidien.',
    'https://archive.org/download/hpr3972/hpr3972.mp3',
    743,
    NULL,
    156,
    NOW() - INTERVAL '7 days'
  ),
  (
    'c1000000-0000-0000-0000-000000000005',
    'a1000000-0000-0000-0000-000000000004',
    'Creer un preset d''equalisation pour vos podcasts',
    'Une methode pour creer un traitement audio reproductible pour vos episodes de podcast. Apprenez a standardiser la qualite sonore de vos productions.',
    'https://archive.org/download/hpr3973/hpr3973.mp3',
    1019,
    NULL,
    298,
    NOW() - INTERVAL '4 days'
  ),
  (
    'c1000000-0000-0000-0000-000000000006',
    'a1000000-0000-0000-0000-000000000004',
    'Decouverte de USBimager',
    'Pourquoi vous devriez utiliser USBimager. Introduction a cet outil pratique pour ecrire des images sur des peripheriques de stockage en toute simplicite.',
    'https://archive.org/download/hpr3974/hpr3974.mp3',
    1019,
    NULL,
    89,
    NOW() - INTERVAL '10 days'
  ),
  (
    'c1000000-0000-0000-0000-000000000007',
    'a1000000-0000-0000-0000-000000000003',
    'Mesa Verde : journal de voyage Colorado',
    'Notre recit d''une journee de visite a Mesa Verde, Colorado. Nous etions la pour un mariage et avons profite pour explorer ce site remarquable.',
    'https://archive.org/download/hpr3975/hpr3975.mp3',
    730,
    NULL,
    321,
    NOW() - INTERVAL '1 day'
  ),
  (
    'c1000000-0000-0000-0000-000000000008',
    'a1000000-0000-0000-0000-000000000004',
    'L''evolution de l''outil Capture d''ecran Windows',
    'KD retrace l''histoire de l''evolution des outils de capture d''ecran sous Windows, du Print Screen au Snipping Tool moderne.',
    'https://archive.org/download/hpr3976/hpr3976.mp3',
    429,
    NULL,
    134,
    NOW() - INTERVAL '6 days'
  ),
  (
    'c1000000-0000-0000-0000-000000000009',
    'a1000000-0000-0000-0000-000000000005',
    'Les trolls du droit d''auteur Creative Commons',
    'Discussion sur Pixsy, un nouveau type de troll du droit d''auteur qui cible les utilisateurs de Creative Commons. Lecture et analyse d''un article de fond sur ce sujet preoccupant.',
    'https://archive.org/download/Cory_Doctorow_Podcast_412/Cory_Doctorow_Podcast_412_-_A_Bug_in_Early_Creative_Commons_Licenses.mp3',
    2441,
    NULL,
    567,
    NOW() - INTERVAL '8 days'
  );

-- 4. Associate tags to podcasts
INSERT INTO public.podcast_tags (podcast_id, tag_id) VALUES
  -- Creative Commons Search Engine
  ('c1000000-0000-0000-0000-000000000001', 'b1000000-0000-0000-0000-000000000002'), -- Open Source
  ('c1000000-0000-0000-0000-000000000001', 'b1000000-0000-0000-0000-000000000001'), -- Technologie
  -- Alpha Centauri
  ('c1000000-0000-0000-0000-000000000002', 'b1000000-0000-0000-0000-000000000003'), -- Jeux Video
  ('c1000000-0000-0000-0000-000000000002', 'b1000000-0000-0000-0000-000000000004'), -- Tutoriel
  -- Comment se faire des amis
  ('c1000000-0000-0000-0000-000000000003', 'b1000000-0000-0000-0000-000000000008'), -- Vie Quotidienne
  ('c1000000-0000-0000-0000-000000000003', 'b1000000-0000-0000-0000-000000000005'), -- Culture
  -- Thunderbird
  ('c1000000-0000-0000-0000-000000000004', 'b1000000-0000-0000-0000-000000000007'), -- Productivite
  ('c1000000-0000-0000-0000-000000000004', 'b1000000-0000-0000-0000-000000000001'), -- Technologie
  -- Equalisation podcast
  ('c1000000-0000-0000-0000-000000000005', 'b1000000-0000-0000-0000-000000000012'), -- Podcasting
  ('c1000000-0000-0000-0000-000000000005', 'b1000000-0000-0000-0000-000000000004'), -- Tutoriel
  -- USBimager
  ('c1000000-0000-0000-0000-000000000006', 'b1000000-0000-0000-0000-000000000011'), -- Linux
  ('c1000000-0000-0000-0000-000000000006', 'b1000000-0000-0000-0000-000000000002'), -- Open Source
  -- Mesa Verde
  ('c1000000-0000-0000-0000-000000000007', 'b1000000-0000-0000-0000-000000000006'), -- Voyage
  ('c1000000-0000-0000-0000-000000000007', 'b1000000-0000-0000-0000-000000000005'), -- Culture
  -- Snipping Tool
  ('c1000000-0000-0000-0000-000000000008', 'b1000000-0000-0000-0000-000000000010'), -- Windows
  ('c1000000-0000-0000-0000-000000000008', 'b1000000-0000-0000-0000-000000000001'), -- Technologie
  -- Cory Doctorow - Copyright trolls
  ('c1000000-0000-0000-0000-000000000009', 'b1000000-0000-0000-0000-000000000009'), -- Droit Numerique
  ('c1000000-0000-0000-0000-000000000009', 'b1000000-0000-0000-0000-000000000002'); -- Open Source

-- 5. Add some likes
INSERT INTO public.likes (user_id, podcast_id) VALUES
  ('a1000000-0000-0000-0000-000000000001', 'c1000000-0000-0000-0000-000000000003'),
  ('a1000000-0000-0000-0000-000000000001', 'c1000000-0000-0000-0000-000000000009'),
  ('a1000000-0000-0000-0000-000000000002', 'c1000000-0000-0000-0000-000000000001'),
  ('a1000000-0000-0000-0000-000000000002', 'c1000000-0000-0000-0000-000000000007'),
  ('a1000000-0000-0000-0000-000000000002', 'c1000000-0000-0000-0000-000000000009'),
  ('a1000000-0000-0000-0000-000000000003', 'c1000000-0000-0000-0000-000000000005'),
  ('a1000000-0000-0000-0000-000000000003', 'c1000000-0000-0000-0000-000000000003'),
  ('a1000000-0000-0000-0000-000000000004', 'c1000000-0000-0000-0000-000000000001'),
  ('a1000000-0000-0000-0000-000000000004', 'c1000000-0000-0000-0000-000000000003'),
  ('a1000000-0000-0000-0000-000000000004', 'c1000000-0000-0000-0000-000000000007'),
  ('a1000000-0000-0000-0000-000000000005', 'c1000000-0000-0000-0000-000000000003'),
  ('a1000000-0000-0000-0000-000000000005', 'c1000000-0000-0000-0000-000000000005'),
  ('a1000000-0000-0000-0000-000000000005', 'c1000000-0000-0000-0000-000000000007');

-- 6. Add some comments
INSERT INTO public.comments (id, user_id, podcast_id, content, created_at) VALUES
  ('d1000000-0000-0000-0000-000000000001', 'a1000000-0000-0000-0000-000000000002', 'c1000000-0000-0000-0000-000000000001', 'Super episode ! Je ne connaissais pas Openverse, merci pour la decouverte.', NOW() - INTERVAL '1 day'),
  ('d1000000-0000-0000-0000-000000000002', 'a1000000-0000-0000-0000-000000000003', 'c1000000-0000-0000-0000-000000000001', 'Tres utile pour trouver du contenu libre. Je recommande aussi ccMixter pour la musique.', NOW() - INTERVAL '12 hours'),
  ('d1000000-0000-0000-0000-000000000003', 'a1000000-0000-0000-0000-000000000001', 'c1000000-0000-0000-0000-000000000003', 'J''adore ce format de discussion decontractee. On s''y retrouve tous un peu !', NOW() - INTERVAL '2 days'),
  ('d1000000-0000-0000-0000-000000000004', 'a1000000-0000-0000-0000-000000000004', 'c1000000-0000-0000-0000-000000000003', 'Tellement vrai ce qui est dit sur les communautes en ligne. Bel episode.', NOW() - INTERVAL '2 days'),
  ('d1000000-0000-0000-0000-000000000005', 'a1000000-0000-0000-0000-000000000005', 'c1000000-0000-0000-0000-000000000009', 'Ce sujet me tient a coeur. Les trolls du copyright sont un vrai probleme pour le libre.', NOW() - INTERVAL '7 days'),
  ('d1000000-0000-0000-0000-000000000006', 'a1000000-0000-0000-0000-000000000001', 'c1000000-0000-0000-0000-000000000005', 'Exactement ce qu''il me fallait pour ameliorer le son de mon podcast. Merci !', NOW() - INTERVAL '3 days'),
  ('d1000000-0000-0000-0000-000000000007', 'a1000000-0000-0000-0000-000000000002', 'c1000000-0000-0000-0000-000000000007', 'Mesa Verde a l''air magnifique. Ca donne envie de voyager !', NOW() - INTERVAL '20 hours'),
  ('d1000000-0000-0000-0000-000000000008', 'a1000000-0000-0000-0000-000000000003', 'c1000000-0000-0000-0000-000000000002', 'Alpha Centauri, quel classique ! J''attends la partie 2 avec impatience.', NOW() - INTERVAL '4 days');

-- 7. Add some follows
INSERT INTO public.follows (follower_id, following_id) VALUES
  ('a1000000-0000-0000-0000-000000000001', 'a1000000-0000-0000-0000-000000000005'),
  ('a1000000-0000-0000-0000-000000000002', 'a1000000-0000-0000-0000-000000000001'),
  ('a1000000-0000-0000-0000-000000000002', 'a1000000-0000-0000-0000-000000000003'),
  ('a1000000-0000-0000-0000-000000000003', 'a1000000-0000-0000-0000-000000000002'),
  ('a1000000-0000-0000-0000-000000000003', 'a1000000-0000-0000-0000-000000000005'),
  ('a1000000-0000-0000-0000-000000000004', 'a1000000-0000-0000-0000-000000000001'),
  ('a1000000-0000-0000-0000-000000000004', 'a1000000-0000-0000-0000-000000000002'),
  ('a1000000-0000-0000-0000-000000000005', 'a1000000-0000-0000-0000-000000000003');
