CREATE FUNCTION api.profile_avatar(
	user_id INTEGER DEFAULT 0
)
RETURNS sys."*/*"
LANGUAGE plpgsql VOLATILE
AS $BODY$
DECLARE
	_default TEXT;
BEGIN
	_default := 'default_avatar_' || MOD(user_id, 25) || '.png';
	RETURN _api.serve_user_or_default_media(
		user_id,
		'avatar'::admin.user_media_type,
		_default
	);
END
$BODY$;

GRANT EXECUTE ON FUNCTION api.profile_avatar(INTEGER)
	TO rest_anon, rest_user;
