-- Add RLS policy to allow providers to view leads they have purchased
CREATE POLICY "Providers can view purchased leads"
ON leads
FOR SELECT
TO public
USING (
  EXISTS (
    SELECT 1
    FROM lead_purchases
    WHERE lead_purchases.lead_id = leads.id
    AND lead_purchases.provider_id = auth.uid()
  )
);

-- Add comment for documentation
COMMENT ON POLICY "Providers can view purchased leads" ON leads IS 
'Allows providers to view full details of leads they have purchased through lead_purchases table';