from django.shortcuts import render
from datetime import datetime, timedelta
import pytz, random

from .models import *
from .serializers import *

from django.db.models import Q

from rest_framework import generics
from rest_framework.decorators import authentication_classes, permission_classes
from rest_framework.authentication import SessionAuthentication, BasicAuthentication

from rest_framework.permissions import IsAuthenticated
from rest_framework_api_key.permissions import HasAPIKey


from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters

from rest_framework.response import Response

td = timedelta(hours=8)
odt = datetime.now() - td

# Create your views here.
class FAQsAPIView(generics.ListAPIView):
    serializer_class = FAQSerializer
    queryset = Faq.objects.filter(published=True).order_by('seq_num')
    # filter_backends = [DjangoFilterBackend, filters.SearchFilter]
    # filterset_fields = ['show_title', 'event_type', 'show_date', 'show_day', 'venue__name']
    # search_fields = ['show_title', 'event_type']


class SocialPostsAPIView(generics.ListAPIView):
    serializer_class = SocialPostSerializer
    queryset = SocialPost.objects.filter(published=True)
    permission_classes = [HasAPIKey]


class SocialLinksListAPIView(generics.ListAPIView):
    serializer_class = SocialLinkSerializer
    queryset = SocialLink.objects.all()[:96]
    permission_classes = [HasAPIKey]


class SocialLinksAPIView(generics.ListAPIView):
    serializer_class = SocialLinkSerializer
    queryset = SocialLink.objects.all()[:50]
    permission_classes = [HasAPIKey]

    def get_queryset(self):
            social_links = list(SocialLink.objects.all()[:96])
            queryset = random.sample(social_links, 32)
            return queryset


class SocialImgsAPIView(generics.ListAPIView):
    serializer_class = SocialImgsSerializer
    queryset = SocialImg.objects.all()[:18]
    permission_classes = [HasAPIKey]


