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 Progetto_View(viewsets.ModelViewSet):
    # authentication_classes = [BasicAuthentication, SessionAuthentication, TokenAuthentication]
    # permission_classes = [DjangoModelPermissions]

    queryset = models.Progetto.objects.all()
    serializer_class = serializers.ProgettoSerializer


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

    queryset = models.ValorizzazioneEconomicaProgetto.objects.all()
    serializer_class = serializers.ValorizzazioneEconomicaProgettoSerializer


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

    queryset = models.Repository.objects.all()
    serializer_class = serializers.RepositorySerializer


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

    queryset = models.TipoRelazione.objects.all()
    serializer_class = serializers.TipoRelazioneSerializer


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

    queryset = models.Attivita.objects.all()
    serializer_class = serializers.AttivitaSerializer


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

    queryset = models.RisorsaChiave.objects.all()
    serializer_class = serializers.RisorsaChiaveSerializer


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

    queryset = models.PropostaDiValore.objects.all()
    serializer_class = serializers.PropostaDiValoreSerializer


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

    queryset = models.CanaleDiDistribuzione.objects.all()
    serializer_class = serializers.CanaleDiDistribuzioneSerializer


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

    queryset = models.SettoreDiMercato.objects.all()
    serializer_class = serializers.SettoreDiMercatoSerializer


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

    queryset = models.FlussoDiRicavi.objects.all()
    serializer_class = serializers.FlussoDiRicaviSerializer


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

    queryset = models.StrutturaDeiCosti.objects.all()
    serializer_class = serializers.StrutturaDeiCostiSerializer


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

    queryset = models.SettoreAzienda.objects.all()
    serializer_class = serializers.SettoreAziendaSerializer


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

    queryset = models.RelazioneConAzienda.objects.all()
    serializer_class = serializers.RelazioneConAziendaSerializer


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

    queryset = models.TipoAttivita.objects.all()
    serializer_class = serializers.TipoAttivitaSerializer


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

    queryset = models.ValoreDelProgetto.objects.all()
    serializer_class = serializers.ValoreDelProgettoSerializer


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

    queryset = models.AttivitaDelProgetto.objects.all()
    serializer_class = serializers.AttivitaDelProgettoSerializer


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

    queryset = models.AssetDelProgetto.objects.all()
    serializer_class = serializers.AssetDelProgettoSerializer


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

    queryset = models.RisorsaPersonale.objects.all()
    serializer_class = serializers.RisorsaPersonaleSerializer


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

    queryset = models.RisorsaFisica.objects.all()
    serializer_class = serializers.RisorsaFisicaSerializer


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

    queryset = models.RisorsaFinanziaria.objects.all()
    serializer_class = serializers.RisorsaFinanziariaSerializer


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

    queryset = models.ValoreDellAttivita.objects.all()
    serializer_class = serializers.ValoreDellAttivitaSerializer


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

    queryset = models.ValorizzazioneEconomicaAttivita.objects.all()
    serializer_class = serializers.ValorizzazioneEconomicaAttivitaSerializer


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

    queryset = models.AssetDaAttivita.objects.all()
    serializer_class = serializers.AssetDaAttivitaSerializer


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

    queryset = models.ArchivioFiles.objects.all()
    serializer_class = serializers.ArchivioFilesSerializer


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

    queryset = models.CanaleDistribuzioneIndiretto.objects.all()
    serializer_class = serializers.CanaleDistribuzioneIndirettoSerializer
