from copy import deepcopy

from django.shortcuts import render, redirect
from django.http import JsonResponse, HttpResponse
from django.utils.http import url_has_allowed_host_and_scheme
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import authenticate, login, logout
from rest_framework import viewsets
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from rest_framework.permissions import DjangoModelPermissions, IsAuthenticated

from django_auto_prefetching import AutoPrefetchViewSetMixin
from . import models
from . import serializers

# def index(request):
#     return HttpResponse("Hello, %s!" % (request.user.username if request.user.is_authenticated else 'World'))

# --------------- FINE PREFISSO TEMPLATE ---------------


class ContattoAziendale_View(viewsets.ModelViewSet):
    # authentication_classes = [BasicAuthentication, SessionAuthentication, TokenAuthentication]
    # permission_classes = [DjangoModelPermissions]

    queryset = models.ContattoAziendale.objects.all()
    serializer_class = serializers.ContattoAziendaleSerializer


class Recapito_View(viewsets.ModelViewSet):
    # authentication_classes = [BasicAuthentication, SessionAuthentication, TokenAuthentication]
    # permission_classes = [DjangoModelPermissions]

    queryset = models.Recapito.objects.all()
    serializer_class = serializers.RecapitoSerializer


class Telefono_View(viewsets.ModelViewSet):
    # authentication_classes = [BasicAuthentication, SessionAuthentication, TokenAuthentication]
    # permission_classes = [DjangoModelPermissions]

    queryset = models.Telefono.objects.all()
    serializer_class = serializers.TelefonoSerializer


class Email_View(viewsets.ModelViewSet):
    # authentication_classes = [BasicAuthentication, SessionAuthentication, TokenAuthentication]
    # permission_classes = [DjangoModelPermissions]

    queryset = models.Email.objects.all()
    serializer_class = serializers.EmailSerializer


class PersonaFisica_View(viewsets.ModelViewSet):
    # authentication_classes = [BasicAuthentication, SessionAuthentication, TokenAuthentication]
    # permission_classes = [DjangoModelPermissions]

    queryset = models.PersonaFisica.objects.all()
    serializer_class = serializers.PersonaFisicaSerializer


class PersonaGiuridica_View(viewsets.ModelViewSet):
    # authentication_classes = [BasicAuthentication, SessionAuthentication, TokenAuthentication]
    # permission_classes = [DjangoModelPermissions]

    queryset = models.PersonaGiuridica.objects.all()
    serializer_class = serializers.PersonaGiuridicaSerializer


class Sede_View(viewsets.ModelViewSet):
    # authentication_classes = [BasicAuthentication, SessionAuthentication, TokenAuthentication]
    # permission_classes = [DjangoModelPermissions]

    queryset = models.Sede.objects.all()
    serializer_class = serializers.SedeSerializer


class Fax_View(viewsets.ModelViewSet):
    # authentication_classes = [BasicAuthentication, SessionAuthentication, TokenAuthentication]
    # permission_classes = [DjangoModelPermissions]

    queryset = models.Fax.objects.all()
    serializer_class = serializers.FaxSerializer


class Pec_View(viewsets.ModelViewSet):
    # authentication_classes = [BasicAuthentication, SessionAuthentication, TokenAuthentication]
    # permission_classes = [DjangoModelPermissions]

    queryset = models.Pec.objects.all()
    serializer_class = serializers.PecSerializer


class SoggettoContattabile_View(viewsets.ModelViewSet):
    # authentication_classes = [BasicAuthentication, SessionAuthentication, TokenAuthentication]
    # permission_classes = [DjangoModelPermissions]

    queryset = models.SoggettoContattabile.objects.all()
    serializer_class = serializers.SoggettoContattabileSerializer


class Indirizzo_View(viewsets.ModelViewSet):
    # authentication_classes = [BasicAuthentication, SessionAuthentication, TokenAuthentication]
    # permission_classes = [DjangoModelPermissions]

    queryset = models.Indirizzo.objects.all()
    serializer_class = serializers.IndirizzoSerializer


class Societa_View(viewsets.ModelViewSet):
    # authentication_classes = [BasicAuthentication, SessionAuthentication, TokenAuthentication]
    # permission_classes = [DjangoModelPermissions]

    queryset = models.Societa.objects.all()
    serializer_class = serializers.SocietaSerializer
