CREATE OR REPLACE FUNCTION public.fn_admin_list_partners(p_filter text DEFAULT 'all'::text)
 RETURNS TABLE(partner_id bigint, name text, surname text, email text, country text, zinzino_range text, is_tutor boolean, is_professor boolean, is_superadmin boolean, is_student boolean, student_count integer)
 LANGUAGE sql
 STABLE
AS $function$
    SELECT partner_id, name::text, surname::text, email::text, country::text, zinzino_range::text,
           is_tutor, is_professor, is_superadmin, is_student, student_count
    FROM public.vw_partner_list
    WHERE (p_filter = 'all'
        OR (p_filter = 'tutor'      AND is_tutor = true)
        OR (p_filter = 'professor'  AND is_professor = true)
        OR (p_filter = 'superadmin' AND is_superadmin = true)
        OR (p_filter = 'student'    AND is_student = true))
    ORDER BY surname, name
    LIMIT 500;
$function$
;
