-- Seed Data for Dirt Development
-- Run this after migrations to populate test data.
--
-- This seed is designed to be:
-- - Deterministic (fixed UUIDs)
-- - Idempotent (safe to re-run)
-- - Useful for Feed/Search/Detail testing (approved reviews with published_at)
--
-- NOTE:
-- - `public.users.id` has a FK to `auth.users.id`, so we seed BOTH.
-- - This is development-only. Do not use in production.

-- ============================================
-- SAMPLE AUTH USERS (for development only)
-- ============================================
-- Minimal auth rows so `public.users` can reference them.
-- We do NOT attempt to make these fully-loginable accounts (identities, providers, etc).
-- For login testing, create real users via the app / Supabase Auth.

INSERT INTO auth.users (
  id,
  instance_id,
  aud,
  role,
  email,
  encrypted_password,
  email_confirmed_at,
  raw_app_meta_data,
  raw_user_meta_data,
  created_at,
  updated_at
)
VALUES
  (
    '00000000-0000-0000-0000-000000000001',
    '00000000-0000-0000-0000-000000000000',
    'authenticated',
    'authenticated',
    'avery.woman@example.com',
    '',
    NOW() - INTERVAL '30 days',
    '{"provider":"email","providers":["email"]}',
    '{"username":"avery"}',
    NOW() - INTERVAL '30 days',
    NOW() - INTERVAL '1 day'
  ),
  (
    '00000000-0000-0000-0000-000000000002',
    '00000000-0000-0000-0000-000000000000',
    'authenticated',
    'authenticated',
    'jordan.man@example.com',
    '',
    NOW() - INTERVAL '20 days',
    '{"provider":"email","providers":["email"]}',
    '{"username":"jordan"}',
    NOW() - INTERVAL '20 days',
    NOW() - INTERVAL '2 days'
  ),
  (
    '00000000-0000-0000-0000-000000000003',
    '00000000-0000-0000-0000-000000000000',
    'authenticated',
    'authenticated',
    'sam.nb@example.com',
    '',
    NOW() - INTERVAL '10 days',
    '{"provider":"email","providers":["email"]}',
    '{"username":"sam"}',
    NOW() - INTERVAL '10 days',
    NOW() - INTERVAL '3 days'
  ),
  (
    '00000000-0000-0000-0000-000000000004',
    '00000000-0000-0000-0000-000000000000',
    'authenticated',
    'authenticated',
    'taylor.pnts@example.com',
    '',
    NULL, -- unverified email for edge-case testing
    '{"provider":"email","providers":["email"]}',
    '{"username":"taylor"}',
    NOW() - INTERVAL '5 days',
    NOW() - INTERVAL '5 days'
  )
ON CONFLICT (id) DO UPDATE SET
  email = EXCLUDED.email,
  updated_at = EXCLUDED.updated_at;

-- ============================================
-- SAMPLE APP USERS (public.users)
-- ============================================
-- Must reference seeded auth.users ids above.
INSERT INTO public.users (
  id,
  email,
  username,
  gender,
  date_of_birth,
  city,
  state,
  country,
  email_verified,
  subscription_tier,
  google_indexing_enabled,
  created_at,
  updated_at,
  last_active_at
)
VALUES
  (
    '00000000-0000-0000-0000-000000000001',
    'avery.woman@example.com',
    'avery',
    'woman',
    '1996-03-15',
    'New York',
    'NY',
    'US',
    TRUE,
    'free',
    TRUE,
    NOW() - INTERVAL '30 days',
    NOW() - INTERVAL '1 day',
    NOW() - INTERVAL '2 hours'
  ),
  (
    '00000000-0000-0000-0000-000000000002',
    'jordan.man@example.com',
    'jordan',
    'man',
    '1993-07-22',
    'Los Angeles',
    'CA',
    'US',
    TRUE,
    'pro_monthly',
    TRUE,
    NOW() - INTERVAL '20 days',
    NOW() - INTERVAL '2 days',
    NOW() - INTERVAL '1 hour'
  ),
  (
    '00000000-0000-0000-0000-000000000003',
    'sam.nb@example.com',
    'sam',
    'non_binary',
    '1995-11-08',
    'Chicago',
    'IL',
    'US',
    TRUE,
    'free',
    TRUE,
    NOW() - INTERVAL '10 days',
    NOW() - INTERVAL '3 days',
    NOW() - INTERVAL '30 minutes'
  ),
  (
    '00000000-0000-0000-0000-000000000004',
    'taylor.pnts@example.com',
    'taylor',
    'prefer_not_to_say',
    '1992-01-30',
    'Austin',
    'TX',
    'US',
    FALSE,
    'free',
    TRUE,
    NOW() - INTERVAL '5 days',
    NOW() - INTERVAL '5 days',
    NOW() - INTERVAL '5 days'
  )
ON CONFLICT (id) DO UPDATE SET
  email = EXCLUDED.email,
  username = EXCLUDED.username,
  gender = EXCLUDED.gender,
  date_of_birth = EXCLUDED.date_of_birth,
  city = EXCLUDED.city,
  state = EXCLUDED.state,
  country = EXCLUDED.country,
  email_verified = EXCLUDED.email_verified,
  subscription_tier = EXCLUDED.subscription_tier,
  google_indexing_enabled = EXCLUDED.google_indexing_enabled,
  updated_at = EXCLUDED.updated_at,
  last_active_at = EXCLUDED.last_active_at;

-- ============================================
-- SAMPLE REVIEWS (for development only)
-- ============================================
-- Approved reviews (appear in feed/search)
INSERT INTO public.reviews (
  id,
  author_id,
  subject_first_name,
  subject_last_name,
  subject_age,
  subject_gender,
  content,
  rating,
  city,
  state,
  country,
  status,
  auto_flagged,
  flagged_keywords,
  is_indexable,
  view_count,
  report_count,
  created_at,
  updated_at,
  published_at
)
VALUES
  (
    '10000000-0000-0000-0000-000000000001',
    '00000000-0000-0000-0000-000000000001',
    'John',
    'Smith',
    28,
    'man',
    'We dated for about three months. He was charming early on, but follow-through was inconsistent: late arrivals, vague excuses, and a pattern of disappearing for days. I wish I had trusted my gut sooner.',
    2,
    'New York',
    'NY',
    'US',
    'approved',
    FALSE,
    NULL,
    TRUE,
    42,
    0,
    NOW() - INTERVAL '8 days',
    NOW() - INTERVAL '8 days',
    NOW() - INTERVAL '8 days'
  ),
  (
    '10000000-0000-0000-0000-000000000002',
    '00000000-0000-0000-0000-000000000003',
    'David',
    'Johnson',
    32,
    'man',
    'Kind, respectful, and consistent. He communicated clearly, planned thoughtful dates, and never made me feel rushed. We ended things because of distance, not drama. I would genuinely recommend him.',
    5,
    'Chicago',
    'IL',
    'US',
    'approved',
    FALSE,
    NULL,
    TRUE,
    17,
    0,
    NOW() - INTERVAL '3 days',
    NOW() - INTERVAL '3 days',
    NOW() - INTERVAL '3 days'
  ),
  (
    '10000000-0000-0000-0000-000000000003',
    '00000000-0000-0000-0000-000000000001',
    'Chris',
    'Williams',
    26,
    'man',
    'Met on an app and went on four solid dates. Then he ghosted without a conversation. No one owes anyone forever, but basic closure matters. If you want consistent communication, proceed carefully.',
    2,
    'New York',
    'NY',
    'US',
    'approved',
    FALSE,
    NULL,
    TRUE,
    9,
    1,
    NOW() - INTERVAL '14 days',
    NOW() - INTERVAL '10 days',
    NOW() - INTERVAL '14 days'
  ),
  (
    '10000000-0000-0000-0000-000000000004',
    '00000000-0000-0000-0000-000000000002',
    'Jennifer',
    'Davis',
    27,
    'woman',
    'Funny, ambitious, and easy to talk to. She was direct about what she wanted and respected my boundaries. We ended things mutually due to schedules, but the experience was positive overall.',
    4,
    'Los Angeles',
    'CA',
    'US',
    'approved',
    FALSE,
    NULL,
    TRUE,
    33,
    0,
    NOW() - INTERVAL '6 days',
    NOW() - INTERVAL '6 days',
    NOW() - INTERVAL '6 days'
  ),
  (
    '10000000-0000-0000-0000-000000000005',
    '00000000-0000-0000-0000-000000000002',
    'Ashley',
    'Miller',
    29,
    'woman',
    'We went on a few dates and it fizzled naturally. She was polite and punctual, but there was no spark on either side. Nothing alarming here—just not a match for me.',
    3,
    'Austin',
    'TX',
    'US',
    'approved',
    FALSE,
    NULL,
    TRUE,
    5,
    0,
    NOW() - INTERVAL '20 days',
    NOW() - INTERVAL '20 days',
    NOW() - INTERVAL '20 days'
  ),
  (
    '10000000-0000-0000-0000-000000000006',
    '00000000-0000-0000-0000-000000000003',
    'Riley',
    'Nguyen',
    30,
    'non_binary',
    'Thoughtful and emotionally mature. They communicated expectations early and kept things honest. We were looking for different levels of seriousness, but the dating experience felt safe and respectful.',
    5,
    'Chicago',
    'IL',
    'US',
    'approved',
    FALSE,
    NULL,
    TRUE,
    12,
    0,
    NOW() - INTERVAL '2 days',
    NOW() - INTERVAL '2 days',
    NOW() - INTERVAL '2 days'
  )
ON CONFLICT (id) DO UPDATE SET
  author_id = EXCLUDED.author_id,
  subject_first_name = EXCLUDED.subject_first_name,
  subject_last_name = EXCLUDED.subject_last_name,
  subject_age = EXCLUDED.subject_age,
  subject_gender = EXCLUDED.subject_gender,
  content = EXCLUDED.content,
  rating = EXCLUDED.rating,
  city = EXCLUDED.city,
  state = EXCLUDED.state,
  country = EXCLUDED.country,
  status = EXCLUDED.status,
  auto_flagged = EXCLUDED.auto_flagged,
  flagged_keywords = EXCLUDED.flagged_keywords,
  is_indexable = EXCLUDED.is_indexable,
  view_count = EXCLUDED.view_count,
  report_count = EXCLUDED.report_count,
  updated_at = EXCLUDED.updated_at,
  published_at = EXCLUDED.published_at;

-- Pending review (should be placed into moderation_queue by trigger)
INSERT INTO public.reviews (
  id,
  author_id,
  subject_first_name,
  subject_last_name,
  subject_age,
  subject_gender,
  content,
  rating,
  city,
  state,
  country,
  status,
  created_at,
  updated_at
)
VALUES
  (
    '10000000-0000-0000-0000-000000000007',
    '00000000-0000-0000-0000-000000000001',
    'Test',
    'Subject',
    25,
    'man',
    'This is a test review intended for the moderation queue. It is pending review and should not appear in the public feed or search results until approved by moderation.',
    3,
    'New York',
    'NY',
    'US',
    'pending_review',
    NOW() - INTERVAL '1 day',
    NOW() - INTERVAL '1 day'
  )
ON CONFLICT (id) DO UPDATE SET
  updated_at = EXCLUDED.updated_at;

-- ============================================
-- SAMPLE RESPONSES (for development only)
-- ============================================
-- Leaving responses empty by default since creation is restricted to ID-verified users.

-- ============================================
-- VERIFICATION RECORDS (for development only)
-- ============================================
-- Leaving verification records empty by default.

-- ============================================
-- NOTES FOR DEVELOPMENT
-- ============================================
-- This seed is intended for quickly getting real review rows into the DB.
-- For end-to-end login testing, create real accounts via Supabase Auth (app flow),
-- since Auth may require additional tables (e.g. identities/providers).
