from fun_views.patterns.detail import detail_render_pattern
from fun_views.views.utils import (get_context_base, make_base_view,
                                   not_set_get_obj, not_set_get_template_name,
                                   prefer_func, prefer_literal,
                                   render_response_base)

detail_render_base = make_base_view(detail_render_pattern)


def detail_render(obj=None,
                  get_obj=not_set_get_obj,
                  obj_context_name='obj',
                  get_obj_context_name=None,
                  get_context=get_context_base,
                  template_name=None,
                  get_template_name=not_set_get_template_name,
                  render_response=render_response_base):
    """
    allow literal values API on top of `template_render_base`, so not every param
    needs to be a function

    :param str template_name:
    :param Callable[[ReqData, Dict], str] get_template_name:
    :param Any obj:
    :param Callable[[ReqData], Any] get_obj:
    :param str obj_context_name:
    :param Callable[[ReqData, Dict], str] get_obj_context_name:
    :param Callable[[ReqData, Dict], Dict] get_context:
    :param Callable[[ReqData, str, Dict], HttpResponse] render_response:
    """
    return detail_render_base(
        prefer_literal(obj, get_obj),
        prefer_func(obj_context_name, get_obj_context_name),
        get_context,
        prefer_literal(template_name, get_template_name),
        render_response
    )
