-- Fix the demo artist account by creating proper artist profile linked to user
-- First, ensure the demo artist user exists and get their ID
DO $$
DECLARE
  artist_user_id UUID;
  artist_profile_id UUID;
BEGIN
  -- Get or create the artist user
  SELECT id INTO artist_user_id FROM users WHERE email = 'artist@musicapp.com';
  
  IF artist_user_id IS NULL THEN
    -- Create artist user if doesn't exist
    INSERT INTO users (id, email, password_hash, name, role, is_active, subscription_type)
    VALUES (
      gen_random_uuid(),
      'artist@musicapp.com',
      '$2a$10$rQEY7lSvBKAYqLf5HnV2NeOKLkGZ.T9ZqVjC5kj8nM3xfP1vYyXZS',
      'Demo Artist',
      'artist',
      true,
      'premium'
    )
    RETURNING id INTO artist_user_id;
  ELSE
    -- Update existing user to be an artist
    UPDATE users 
    SET role = 'artist', subscription_type = 'premium'
    WHERE id = artist_user_id;
  END IF;
  
  -- Check if artist profile already exists for this user
  SELECT id INTO artist_profile_id FROM artists WHERE user_id = artist_user_id;
  
  IF artist_profile_id IS NULL THEN
    -- Create new artist profile
    INSERT INTO artists (id, user_id, name, bio, is_verified)
    VALUES (
      gen_random_uuid(),
      artist_user_id,
      'Demo Artist',
      'Demo artist account for testing',
      true
    );
  END IF;
END $$;
