-- Add SELECT policy for providers to view available leads
-- Providers can view leads that have consent and are available (new status)

CREATE POLICY "Providers can view available leads"
  ON leads
  FOR SELECT
  TO public
  USING (
    consent_given = true 
    AND status = 'new'
    AND EXISTS (
      SELECT 1 
      FROM profiles 
      WHERE profiles.id = auth.uid() 
        AND profiles.role = 'provider'
    )
  );