{"-- Add RLS policies for camera management
-- Allow organization admins and managers to manage cameras

CREATE POLICY \"Admins and managers can update cameras\"
ON public.cameras
FOR UPDATE
USING (
  EXISTS (
    SELECT 1 
    FROM user_roles ur
    JOIN branches b ON ur.organization_id = b.organization_id
    WHERE ur.user_id = auth.uid() 
    AND b.id = cameras.branch_id 
    AND ur.role IN ('admin', 'manager')
  )
)","CREATE POLICY \"Admins and managers can insert cameras\"
ON public.cameras
FOR INSERT
WITH CHECK (
  EXISTS (
    SELECT 1 
    FROM user_roles ur
    JOIN branches b ON ur.organization_id = b.organization_id
    WHERE ur.user_id = auth.uid() 
    AND b.id = cameras.branch_id 
    AND ur.role IN ('admin', 'manager')
  )
)","CREATE POLICY \"Admins and managers can delete cameras\"
ON public.cameras
FOR DELETE
USING (
  EXISTS (
    SELECT 1 
    FROM user_roles ur
    JOIN branches b ON ur.organization_id = b.organization_id
    WHERE ur.user_id = auth.uid() 
    AND b.id = cameras.branch_id 
    AND ur.role IN ('admin', 'manager')
  )
)"}