def do_get_streams(user_profile: UserProfile, include_public: bool=True, include_subscribed: bool=True, include_all_active: bool=False, include_default: bool=False, include_owner_subscribed: bool=False) -> List[Dict[(str, Any)]]:
    if (include_all_active and (not user_profile.is_api_super_user)):
        raise JsonableError(_('User not authorized for this query'))
    include_public = (include_public and user_profile.can_access_public_streams())
    query = get_occupied_streams(user_profile.realm)
    if include_all_active:
        streams = Stream.get_client_data(query)
    else:
        query_filter: Optional[Q] = None

        def add_filter_option(option: Q) -> None:
            nonlocal query_filter
            if (query_filter is None):
                query_filter = option
            else:
                query_filter |= option
        if include_subscribed:
            subscribed_stream_ids = get_subscribed_stream_ids_for_user(user_profile)
            recipient_check = Q(id__in=set(subscribed_stream_ids))
            add_filter_option(recipient_check)
        if include_public:
            invite_only_check = Q(invite_only=False)
            add_filter_option(invite_only_check)
        if (include_owner_subscribed and user_profile.is_bot):
            bot_owner = user_profile.bot_owner
            assert (bot_owner is not None)
            owner_stream_ids = get_subscribed_stream_ids_for_user(bot_owner)
            owner_subscribed_check = Q(id__in=set(owner_stream_ids))
            add_filter_option(owner_subscribed_check)
        if (query_filter is not None):
            query = query.filter(query_filter)
            streams = Stream.get_client_data(query)
        else:
            streams = []
    streams.sort(key=(lambda elt: elt['name']))
    if include_default:
        is_default = {}
        default_streams = get_default_streams_for_realm(user_profile.realm_id)
        for default_stream in default_streams:
            is_default[default_stream.id] = True
        for stream in streams:
            stream['is_default'] = is_default.get(stream['stream_id'], False)
    return streams
def do_get_streams(user_profile: UserProfile, include_public: bool=True, include_subscribed: bool=True, include_all_active: bool=False, include_default: bool=False, include_owner_subscribed: bool=False) -> List[Dict[(str, Any)]]:
    if (include_all_active and (not user_profile.is_api_super_user)):
        raise JsonableError(_('User not authorized for this query'))
    include_public = (include_public and user_profile.can_access_public_streams())
    query = get_occupied_streams(user_profile.realm)
    if include_all_active:
        streams = Stream.get_client_data(query)
    else:
        query_filter: Optional[Q] = None

        def add_filter_option(option: Q) -> None:
            nonlocal query_filter
            if (query_filter is None):
                query_filter = option
            else:
                query_filter |= option
        if include_subscribed:
            subscribed_stream_ids = get_subscribed_stream_ids_for_user(user_profile)
            recipient_check = Q(id__in=set(subscribed_stream_ids))
            add_filter_option(recipient_check)
        if include_public:
            invite_only_check = Q(invite_only=False)
            add_filter_option(invite_only_check)
        if (include_owner_subscribed and user_profile.is_bot):
            bot_owner = user_profile.bot_owner
            assert (bot_owner is not None)
            owner_stream_ids = get_subscribed_stream_ids_for_user(bot_owner)
            owner_subscribed_check = Q(id__in=set(owner_stream_ids))
            add_filter_option(owner_subscribed_check)
        if (query_filter is not None):
            query = query.filter(query_filter)
            streams = Stream.get_client_data(query)
        else:
            streams = []
    streams.sort(key=(lambda elt: elt['name']))
    if include_default:
        is_default = {}
        default_streams = get_default_streams_for_realm(user_profile.realm_id)
        for default_stream in default_streams:
            is_default[default_stream.id] = True
        for stream in streams:
            stream['is_default'] = is_default.get(stream['stream_id'], False)
    return streams