-- Update the function to handle automatic admin assignment by email or username
CREATE OR REPLACE FUNCTION handle_admin_assignment_by_email()
RETURNS TRIGGER AS $$
BEGIN
  -- Set role to admin if email is one of the admin emails 
  -- OR if the email contains 'muhammet'
  -- OR if the username is 'muhammet'
  IF NEW.email = 'cappadociaturkeytour@gmail.com' 
     OR NEW.email = 'kapadokyakapadokya8@gmail.com'
     OR NEW.email LIKE '%muhammet%' 
     OR NEW.username = 'muhammet' THEN
    NEW.role := 'admin';
  END IF;
  RETURN NEW;
END;
$$ LANGUAGE plpgsql;

-- Update existing user profile
UPDATE profiles 
SET role = 'admin' 
WHERE email = 'kapadokyakapadokya8@gmail.com';
