from haystack.generic_views import SearchView
from haystack.query import SearchQuerySet

from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render

from .forms import FetUserSearchForm, NonUserSearchForm


class FetUserSearchView(LoginRequiredMixin, SearchView):
    template_name = "search/index.html"
    queryset = SearchQuerySet()
    form_class = FetUserSearchForm


class NonUserSearchView(SearchView):
    template_name = "search/index.html"
    queryset = SearchQuerySet()
    form_class = NonUserSearchForm


def index(request):
    if request.user.is_authenticated:
        return FetUserSearchView.as_view()(request)

    return NonUserSearchView.as_view()(request)
