-- Phase 1: Fix Realtime Subscriptions - Add realtime access helper function
-- Note: Realtime schema permissions are managed by Supabase automatically
-- Tables are already in the supabase_realtime publication with REPLICA IDENTITY FULL

-- Create a function to verify realtime access for moderators
CREATE OR REPLACE FUNCTION public.check_realtime_access()
RETURNS boolean
LANGUAGE plpgsql
STABLE SECURITY DEFINER
SET search_path = public
AS $$
BEGIN
  -- Check if user is a moderator (can access realtime moderation features)
  RETURN is_moderator(auth.uid());
END;
$$;

-- Add comment to the function
COMMENT ON FUNCTION public.check_realtime_access() IS 'Checks if the current user has permission to access realtime moderation features. Returns true for moderators, admins, and superusers.';