-- Seed Personal Intel for Michael McLoughlin (Test Data)
-- This adds sample personal intel to demonstrate the Personal Profile feature

DO $$
DECLARE
  v_lead_id UUID;
BEGIN
  -- Try to find existing lead named Michael McLoughlin or similar
  SELECT id INTO v_lead_id
  FROM leads
  WHERE (first_name ILIKE '%michael%' AND last_name ILIKE '%loughlin%')
     OR (first_name ILIKE '%michael%' AND last_name ILIKE '%rocco%')
  ORDER BY created_at DESC
  LIMIT 1;

  -- If no lead found, create one
  IF v_lead_id IS NULL THEN
    INSERT INTO leads (first_name, last_name, company, source, status, score)
    VALUES ('Michael', 'McLoughlin', 'Formcork Steelfixin', 'test', 'new', 75)
    RETURNING id INTO v_lead_id;
  END IF;

  -- Delete existing intel for this lead (if any)
  DELETE FROM lead_intel WHERE lead_id = v_lead_id;

  -- Insert fresh personal intel
  INSERT INTO lead_intel (
    lead_id,
    family_status,
    hobbies,
    interests,
    location_suburb,
    personality_notes,
    conversation_starters,
    personal_news
  ) VALUES (
    v_lead_id,
    'Irish expat, 44 years old',
    ARRAY['Following F1', 'Watching football', 'Watching NRL', 'Grew up working in family pub'],
    ARRAY['Liverpool FC supporter', 'South Sydney Rabbitohs fan', 'F1 Racing - Max Verstappen', 'Construction industry', 'Irish heritage'],
    'Sydney (from Achill Island, Ireland)',
    'Irish heritage, grew up in a pub on Achill Island. Passionate about sports - Liverpool FC supporter, follows Rabbitohs in NRL, big F1 fan backing Max Verstappen. Works in construction at Formcork Steelfixin.',
    ARRAY[
      'Ask about Liverpool''s season - he''s a big Reds supporter',
      'Mention the F1 - Max Verstappen is his driver',
      'Ask how the Rabbitohs are going this NRL season',
      'Growing up in a pub on Achill Island - great stories there',
      'Construction chat - Formcork Steelfixin and concrete work'
    ],
    '{"origin": "Achill Island, Ireland", "fun_fact": "Grew up in a pub", "age": 44, "favorite_f1_driver": "Max Verstappen", "sports_teams": ["Liverpool FC", "South Sydney Rabbitohs"]}'::JSONB
  );
END $$;
