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

    queryset = models.ModalitaLavoro.objects.all()
    serializer_class = serializers.ModalitaLavoroSerializer


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

    queryset = models.AtomoFatturabile.objects.all()
    serializer_class = serializers.DettaglioFatturabileSerializer


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

    queryset = models.FatturaElettronica.objects.all()
    serializer_class = serializers.FatturaElettronicaSerializer


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

    queryset = models.RegimeFiscale.objects.all()
    serializer_class = serializers.RegimeFiscaleSerializer


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

    queryset = models.TipoCassa.objects.all()
    serializer_class = serializers.TipoCassaSerializer


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

    queryset = models.ModalitaPagamento.objects.all()
    serializer_class = serializers.ModalitaPagamentoSerializer


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

    queryset = models.TipoDocumento.objects.all()
    serializer_class = serializers.TipoDocumentoSerializer


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

    queryset = models.Natura.objects.all()
    serializer_class = serializers.NaturaSerializer


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

    queryset = models.TipoRitenuta.objects.all()
    serializer_class = serializers.TipoRitenutaSerializer


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

    queryset = models.XmlFatturaElettronica.objects.all()
    serializer_class = serializers.XmlFatturaElettronicaSerializer


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

    queryset = models.SoggettiFatturaElettronica.objects.all()
    serializer_class = serializers.SoggettiFatturaElettronicaSerializer


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

    queryset = models.SoggettoFiscale.objects.all()
    serializer_class = serializers.SoggettoFiscaleSerializer


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

    queryset = models.PartitaIvaCF.objects.all()
    serializer_class = serializers.PartitaIvaCFSerializer


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

    queryset = models.Nazione.objects.all()
    serializer_class = serializers.NazioneSerializer


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

    queryset = models.FormatoTrasmissione.objects.all()
    serializer_class = serializers.FormatoTrasmissioneSerializer


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

    queryset = models.CodiceDestinatario.objects.all()
    serializer_class = serializers.CodiceDestinatarioSerializer


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

    queryset = models.DatoDiContatto.objects.all()
    serializer_class = serializers.DatoDiContattoSerializer


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

    queryset = models.IscrizioneAlboProfessionale.objects.all()
    serializer_class = serializers.IscrizioneAlboProfessionaleSerializer


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

    queryset = models.IscrizioneREA.objects.all()
    serializer_class = serializers.IscrizioneREASerializer


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

    queryset = models.SocioUnico.objects.all()
    serializer_class = serializers.SocioUnicoSerializer


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

    queryset = models.StatoLiquidazione.objects.all()
    serializer_class = serializers.StatoLiquidazioneSerializer


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

    queryset = models.TerzoIntermediarioOSoggettoEmittente.objects.all()
    serializer_class = serializers.TerzoIntermediarioOSoggettoEmittenteSerializer


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

    queryset = models.SoggettoEmittente.objects.all()
    serializer_class = serializers.SoggettoEmittenteSerializer


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

    queryset = models.AlboProfessionale.objects.all()
    serializer_class = serializers.AlboProfessionaleSerializer


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

    queryset = models.Allegato.objects.all()
    serializer_class = serializers.AllegatoSerializer


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

    queryset = models.DatoPagamento.objects.all()
    serializer_class = serializers.DatoPagamentoSerializer


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

    queryset = models.DatiVeicoli.objects.all()
    serializer_class = serializers.DatiVeicoliSerializer


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

    queryset = models.DatiDocumentali.objects.all()
    serializer_class = serializers.DatiDocumentaliSerializer


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

    queryset = models.DatiFattureCollegate.objects.all()
    serializer_class = serializers.DatiFattureCollegateSerializer


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

    queryset = models.DatiSAL.objects.all()
    serializer_class = serializers.DatiSALSerializer


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

    queryset = models.DatiDDT.objects.all()
    serializer_class = serializers.DatiDDTSerializer


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

    queryset = models.DatiTrasporto.objects.all()
    serializer_class = serializers.DatiTrasportoSerializer


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

    queryset = models.Valuta.objects.all()
    serializer_class = serializers.ValutaSerializer


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

    queryset = models.DatiRitenuta.objects.all()
    serializer_class = serializers.DatiRitenutaSerializer


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

    queryset = models.CausalePagamento.objects.all()
    serializer_class = serializers.CausalePagamentoSerializer


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

    queryset = models.DatiBollo.objects.all()
    serializer_class = serializers.DatiBolloSerializer


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

    queryset = models.DatiCassaPrevidenziale.objects.all()
    serializer_class = serializers.DatiCassaPrevidenzialeSerializer


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

    queryset = models.ScontoMaggiorazione.objects.all()
    serializer_class = serializers.ScontoMaggiorazioneSerializer


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

    queryset = models.TipoScontoMaggiorazione.objects.all()
    serializer_class = serializers.TipoScontoMaggiorazioneSerializer


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

    queryset = models.AliquotaIva.objects.all()
    serializer_class = serializers.AliquotaIvaSerializer


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

    queryset = models.ContoBancario.objects.all()
    serializer_class = serializers.ContoBancarioSerializer


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

    queryset = models.IstitutoFinanziario.objects.all()
    serializer_class = serializers.IstitutoFinanziarioSerializer


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

    queryset = models.DettaglioBancario.objects.all()
    serializer_class = serializers.DettaglioBancarioSerializer


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

    queryset = models.CondizionePagamento.objects.all()
    serializer_class = serializers.CondizionePagamentoSerializer


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

    queryset = models.DettaglioLinee.objects.all()
    serializer_class = serializers.DettaglioLineeSerializer


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

    queryset = models.altroDatoGestionale.objects.all()
    serializer_class = serializers.altroDatoGestionaleSerializer


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

    queryset = models.TipoCessionePrestazione.objects.all()
    serializer_class = serializers.TipoCessionePrestazioneSerializer


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

    queryset = models.CodiceArticolo.objects.all()
    serializer_class = serializers.CodiceArticoloSerializer


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

    queryset = models.TipoCodiceArticolo.objects.all()
    serializer_class = serializers.TipoCodiceArticoloSerializer


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

    queryset = models.ArticoloLinea.objects.all()
    serializer_class = serializers.ArticoloLineaSerializer


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

    queryset = models.UnitaMisura.objects.all()
    serializer_class = serializers.UnitaMisuraSerializer


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

    queryset = models.TipoResa.objects.all()
    serializer_class = serializers.TipoResaSerializer


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

    queryset = models.RiferimentoDDTNumeroLinea.objects.all()
    serializer_class = serializers.RiferimentoDDTNumeroLineaSerializer


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

    queryset = models.RiferimentoOrdineAcquistoNumeroLinea.objects.all()
    serializer_class = serializers.RiferimentoOrdineAcquistoNumeroLineaSerializer


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

    queryset = models.CodiciDocumentali.objects.all()
    serializer_class = serializers.CodiciDocumentaliSerializer


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

    queryset = models.TipologiaDocumentale.objects.all()
    serializer_class = serializers.TipologiaDocumentaleSerializer


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

    queryset = models.OggettoDaFatturare.objects.all()
    serializer_class = serializers.DatiEstesiDettaglioFatturabileSerializer


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

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


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

    queryset = models.Provincia.objects.all()
    serializer_class = serializers.ProvinciaSerializer
