from django.contrib.auth.models import User
from rest_framework import generics, permissions
from rest_framework.response import Response
from meetings.models import Meeting
from meetings.serializers import MeetingSerializer, UserSerializer
from meetings.permissions import OnlyUserCanAccess
#from django.http import HttpResponse, JsonResponse, Http404
#from django.views.decorators.csrf import csrf_exempt
#from rest_framework import mixins, status
#from rest_framework.renderers import JSONRenderer
#from rest_framework.parsers import JSONParser
#from rest_framework.decorators import api_view
#from rest_framework.views import APIView

class MeetingList(generics.ListCreateAPIView):
    queryset = Meeting.objects.all()
    serializer_class = MeetingSerializer
    def perform_create(self, serializer):
        serializer.save(user=self.request.user)
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)

class MeetingDetail(generics.RetrieveUpdateDestroyAPIView):
    queryset = Meeting.objects.all()
    serializer_class = MeetingSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly, OnlyUserCanAccess)

class UserList(generics.ListAPIView):
    queryset = User.objects.all()
    serializer_class = UserSerializer

class UserDetail(generics.RetrieveAPIView):
    queryset = User.objects.all()
    serializer_class = UserSerializer
