import json
from django.contrib.auth.decorators import login_required
from django.apps import apps
from django.http import HttpResponse
from accrete.contrib.ui.filter import Filter


@login_required
def params(request, filter_id, model: str):
    app_label, model_name = model.split('.')
    Model = apps.get_model(app_label, model_name)
    return HttpResponse(Filter(Model, request.GET, filter_id=filter_id).query_params())


@login_required
def set_filter_input(request, filter_id, model: str):
    app_label, model_name = model.split('.')
    Model = apps.get_model(app_label, model_name)
    lookup = request.GET.get('lookup')
    return HttpResponse(Filter(Model, request.GET, filter_id=filter_id).query_input(lookup))


@login_required
def tags(request, filter_id, model: str):
    app_label, model_name = model.split('.')
    Model = apps.get_model(app_label, model_name)
    return HttpResponse(Filter(Model, request.GET, filter_id=filter_id).query_tags())
