CREATE OR REPLACE FUNCTION public.fn_professor_list_session_participants(p_session_id integer)
 RETURNS TABLE(full_name text, email text, participant_type text, breakout_room text, has_zoom_link boolean, attended boolean)
 LANGUAGE sql
 STABLE
AS $function$
  SELECT
    sp.full_name,
    sp.email,
    sp.participant_type::text,
    sp.breakout_room::text,
    sp.zoom_join_url IS NOT NULL  AS has_zoom_link,
    sp.attended
  FROM public.session_participants sp
  WHERE sp.session_id = p_session_id
  ORDER BY
    CASE sp.participant_type
      WHEN 'PROFESSOR' THEN 1
      WHEN 'TUTOR'     THEN 2
      ELSE                  3
    END,
    sp.full_name;
$function$
;
