from fun_views.utils import all_args_callable


@all_args_callable
def redirect_view_pattern(get_url,
                          get_query_string,
                          get_use_query_string,
                          get_permanent,
                          do_redirect):
    """
    :param Callable[[], str] get_url:
    :param Callable[[], str] get_query_string:
    :param Callable[[], bool] get_permanent:
    :param Callable[[], bool] get_use_query_string:
    :param Callable[[], HttpResponse] do_redirect:
    """
    url = get_url()
    query_string = get_query_string()

    if get_use_query_string(query_string):
        url = "{}?{}".format(url, query_string)

    return do_redirect(url, get_permanent(url))
